From 4cb41235fe62b4345213c6cc3370ea87918b8be5 Mon Sep 17 00:00:00 2001
From: Lionel Vidaller <lvidaller@grandlyon.com>
Date: Thu, 21 Jan 2021 18:47:46 +0100
Subject: [PATCH] fix housenumber bug caused by non-integer 'numero' in address
 file

---
 bal2osm/bal_2_osm.py  | 56 ++++++++++---------------------------------
 nominatim-3.5/init.sh |  6 ++++-
 2 files changed, 17 insertions(+), 45 deletions(-)

diff --git a/bal2osm/bal_2_osm.py b/bal2osm/bal_2_osm.py
index 2bf675d..2c7a4e7 100644
--- a/bal2osm/bal_2_osm.py
+++ b/bal2osm/bal_2_osm.py
@@ -1,17 +1,10 @@
 #!/usr/bin/env python
 # coding: utf-8
 
-# In[1]:
-
 import sys
 import pandas as pd
 import osmium
 
-
-# In[2]:
-
-
-#fichier_bal = './bal_extrait.csv'
 fichier_bal = sys.argv[1]+'/bal_200046977.csv'
 fichier_codes = './correspondance-code-insee-code-postal-gl.csv'
 fichier_pbf =  sys.argv[1]+'/'+sys.argv[2]
@@ -22,18 +15,24 @@ fichier_pbf =  sys.argv[1]+'/'+sys.argv[2]
 start_id = 1000
 
 
-# In[3]:
-
-
 df = pd.read_csv(fichier_bal,sep=';',header=0,index_col='cle_producteur',decimal='.',encoding='utf-8')
 
 df = df.drop(['x', 'y'], axis=1)
 
+if df['numero'].isnull().sum() > 0:
+    dk = df['numero']
+    index_with_nan = dk.index[dk.isnull()]
+    dk.drop(index_with_nan,0, inplace=True)
+
 # remplacement des valeurs nulles à '' dans 'numero'
 df.loc[df['numero'].isnull(), 'numero'] = ''
 df = df.astype({'numero': str})
-# les entiers ont été transformés en flottant (.0) dans l'opération, suppression de la décimale
-df['numero'] = df['numero'].str[:-2]
+
+# teste si les valeurs non nulles sont des entiers
+if dk.astype(str).str.match("^[0-9]+.0$").all():
+    # si oui, les entiers ont été transformés en flottant (.0) dans l'opération, suppression de la décimale
+    df['numero'] = df['numero'].str[:-2]
+
 df['numero'] = df['numero'].replace('99999', '')
 
 # remplacement des valeurs nulles à '' dans 'suffixe'
@@ -48,39 +47,17 @@ df['addr:housenumber'] = df.numero.str.cat(df.suffixe,sep='')
 
 df.rename(columns={'voie_nom': 'addr:street', 'commune_nom': 'addr:city', 'long': 'lon', 'date_der_maj': 'timestamp'}, inplace=True)
 
-df.dtypes
-
-
-# In[4]:
-
-
-df
-
-
-# In[5]:
-
 
 df_codes = pd.read_csv(fichier_codes,sep=';',header=0,index_col=False,decimal='.',encoding='utf-8')
 del df_codes['Commune']
 df_codes.rename(columns={'Code INSEE': 'insee', 'Code Postal': 'addr:postcode'}, inplace=True)
 df_codes = df_codes.astype({'addr:postcode': str})
 
-df_codes.dtypes
-
-
-# In[6]:
-
 
 df = pd.merge(df, df_codes, on='insee')
 
-df.head()
-
-
-# In[7]:
-
-
-
 
+# écriture du fichier osm.pbf
 writer = osmium.SimpleWriter(fichier_pbf)
 
 i = 0
@@ -103,12 +80,3 @@ for index, row in df.iterrows():
     i += 1
 
 writer.close()
-
-
-# In[ ]:
-
-
-
-
-
-# In[ ]:
diff --git a/nominatim-3.5/init.sh b/nominatim-3.5/init.sh
index bbd0427..00e686f 100644
--- a/nominatim-3.5/init.sh
+++ b/nominatim-3.5/init.sh
@@ -9,13 +9,17 @@ chown postgres:postgres /data/$PGDIR && \
 
 export  PGDATA=/data/$PGDIR  && \
 sudo -u postgres /usr/lib/postgresql/12/bin/initdb -D /data/$PGDIR && \
+
+echo "host all  all    0.0.0.0/0  trust" >> /data/$PGDIR/pg_hba.conf
+echo "listen_addresses='*'" >> /data/$PGDIR/postgresql.conf
+
 sudo -u postgres /usr/lib/postgresql/12/bin/pg_ctl -D /data/$PGDIR start && \
 sudo -u postgres psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='nominatim'" | grep -q 1 || sudo -u postgres createuser -s nominatim && \
 sudo -u postgres psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='www-data'" | grep -q 1 || sudo -u postgres createuser -SDR www-data && \
 sudo -u postgres psql postgres -c "DROP DATABASE IF EXISTS nominatim" && \
 useradd -m -p password1234 nominatim && \
 chown -R nominatim:nominatim ./src && \
-sudo -u nominatim ./src/build/utils/setup.php --osm-file $OSMFILE --all --threads $THREADS && \
+sudo -u nominatim ./src/build/utils/setup.php --osm-file $OSMFILE --all --threads $THREADS --osm2pgsql-cache 1000 && \
 sudo -u nominatim ./src/build/utils/check_import_finished.php && \
 sudo -u postgres /usr/lib/postgresql/12/bin/pg_ctl -D /data/$PGDIR stop && \
 sudo chown -R postgres:postgres /data/$PGDIR
-- 
GitLab