Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(options): ajout d'une option pour utilisation de --flat-nodes #1

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
46 changes: 41 additions & 5 deletions import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down
21 changes: 19 additions & 2 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"