diff --git a/README.md b/README.md index 478dd40..f88ac52 100644 --- a/README.md +++ b/README.md @@ -41,13 +41,14 @@ export OSM_PLANET_URL=https://download.geofabrik.de/europe/monaco-latest.osm.pbf #export OSM_PLANET_URL=https://download.geofabrik.de/europe/france-latest.osm.pbf # Espagne +#export CACHE_SIZE=2000 #export OSM_PLANET_URL=http://download.geofabrik.de/europe/spain-latest.osm.pbf # Côte d'ivoire #export OSM_PLANET_URL=https://download.geofabrik.de/africa/ivory-coast-latest.osm.pbf # Monde entier -#export CACHE_SIZE=20000 +#export USE_FLAT_NODES=1 #export OSM_PLANET_URL=https://planet.openstreetmap.org/pbf/planet-latest.osm.pbf bash osm2pgsql/import.sh @@ -81,7 +82,7 @@ bash import.sh ## TODO -* Ajouter une option `USE_CACHE_NODES` à false par défaut +* Ajouter une option `USE_FLAT_NODES` à false par défaut * Créer un utilisateur "osmrw" et un utilisateur "osmro" * Vérifier la possibilité de faire le lien avec un serveur de tuile (invalidation des tuiles) diff --git a/import.sh b/import.sh index c5e807f..cdafc43 100644 --- a/import.sh +++ b/import.sh @@ -10,18 +10,45 @@ OSM_STYLES_DIR=${SCRIPT_DIR}/styles OSM_CARTO_DIR=${OSM_STYLES_DIR}/openstreetmap-carto #-------------------------------------------------------------- -# Handle params +# Handle import / update options #-------------------------------------------------------------- OSM_DATA_DIR=${OSM_DATA_DIR:-${SCRIPT_DIR}/data} +# optionnal +OSM_FLAT_NODES_PATH=${OSM_DATA_DIR}/nodes.raw PGDATABASE=${PGDATABASE:-osm} echo "[INFO] PGDATABASE=${PGDATABASE}" +# handle cache options +CACHE_SIZE=${CACHE_SIZE:-2000} +echo "[INFO] CACHE_SIZE=${CACHE_SIZE}" +OPTS_CACHE="--cache=$CACHE_SIZE" + +USE_FLAT_NODES=${USE_FLAT_NODES:-0} +echo "[INFO] USE_FLAT_NODES=${USE_FLAT_NODES}" +if [ "$USE_FLAT_NODES" != "0" ]; +then + OPTS_CACHE="--flat-nodes ${OSM_FLAT_NODES_PATH} --cache=0" +fi + +echo "[DEBUG] OPTS_CACHE=${OPTS_CACHE}" + +#-------------------------------------------------------------- +# Handle import specific options +#-------------------------------------------------------------- + OSM_PLANET_URL=${OSM_PLANET_URL:-https://download.geofabrik.de/europe/monaco-latest.osm.pbf} echo "[INFO] OSM_PLANET_URL=${OSM_PLANET_URL}" -CACHE_SIZE=${CACHE_SIZE:-2000} -echo "[INFO] CACHE_SIZE=${CACHE_SIZE}" +FORCE_DOWNLOAD=${FORCE_DOWNLOAD:-0} +echo "[INFO] FORCE_DOWNLOAD=${FORCE_DOWNLOAD}" + +#-------------------------------------------------------------- +# Create osm database +#-------------------------------------------------------------- +createdb $PGDATABASE +CREATE_DB=${CREATE_DB:-1} +echo "[INFO] CREATE_DB=${CREATE_DB}" #-------------------------------------------------------------- # Create osm database @@ -50,7 +77,15 @@ python3 "scripts/get-external-data.py" \ # Download OSM data #-------------------------------------------------------------- mkdir -p $OSM_DATA_DIR -wget -O "$OSM_DATA_DIR/osm.pbf" $OSM_PLANET_URL +if [ ! -e "$OSM_DATA_DIR/osm.pbf" ] || [ "$FORCE_DOWNLOAD" != "0" ] ; +then + wget -O "$OSM_DATA_DIR/osm.pbf" $OSM_PLANET_URL +fi + +#-------------------------------------------------------------- +# Remove existing flat-nodes +#-------------------------------------------------------------- +rm -rf "${OSM_FLAT_NODES_PATH}" #-------------------------------------------------------------- # Import OSM file to PostgreSQL @@ -61,7 +96,8 @@ osm2pgsql \ --slim \ --hstore \ --multi-geometry \ - --cache=$CACHE_SIZE \ + --log-progress=true \ + ${OPTS_CACHE} \ --style="${OSM_CARTO_DIR}/openstreetmap-carto.style" \ --tag-transform-script="${OSM_CARTO_DIR}/openstreetmap-carto.lua" \ "$OSM_DATA_DIR/osm.pbf" diff --git a/update.sh b/update.sh index d63e64f..1d4c049 100644 --- a/update.sh +++ b/update.sh @@ -10,13 +10,28 @@ OSM_STYLES_DIR=${SCRIPT_DIR}/styles OSM_CARTO_DIR=${OSM_STYLES_DIR}/openstreetmap-carto #-------------------------------------------------------------- -# Handle params +# Handle import / update options #-------------------------------------------------------------- +OSM_DATA_DIR=${OSM_DATA_DIR:-${SCRIPT_DIR}/data} +# optionnal +OSM_FLAT_NODES_PATH=${OSM_DATA_DIR}/nodes.raw PGDATABASE=${PGDATABASE:-osm} +echo "[INFO] PGDATABASE=${PGDATABASE}" +# handle cache options CACHE_SIZE=${CACHE_SIZE:-2000} echo "[INFO] CACHE_SIZE=${CACHE_SIZE}" +OPTS_CACHE="--cache=$CACHE_SIZE" + +USE_FLAT_NODES=${USE_FLAT_NODES:-0} +echo "[INFO] USE_FLAT_NODES=${USE_FLAT_NODES}" +if [ "$USE_FLAT_NODES" != "0" ]; +then + OPTS_CACHE="--flat-nodes ${OSM_FLAT_NODES_PATH} --cache=0" +fi + +echo "[INFO] OPTS_CACHE=${OPTS_CACHE}" #-------------------------------------------------------------- # Download openstreetmap-carto if required @@ -34,6 +49,8 @@ osm2pgsql-replication update --verbose -- \ --slim \ --hstore \ --multi-geometry \ - --cache=$CACHE_SIZE \ + --log-progress=true \ + ${OPTS_CACHE} \ --style="${OSM_CARTO_DIR}/openstreetmap-carto.style" \ --tag-transform-script="${OSM_CARTO_DIR}/openstreetmap-carto.lua" +