Installing osmium to merge pbf files for import. Handling merging of multiple pbf files in import script.

This commit is contained in:
Roland 2022-10-27 20:21:50 -06:00
parent a880bf12f8
commit 2b84831205
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 48 additions and 12 deletions

View file

@ -1,4 +1,6 @@
#!/bin/bash
#!/bin/bash -ex
MERGED_TMP_FILE=/tmp/wrolpi-merged.osm.pbf
if [ ! -f /opt/openstreetmap-carto/openstreetmap-carto.lua ]; then
echo "openstreetmap-carto.lua file is missing. Has install been completed?"
@ -15,20 +17,54 @@ if [ "${1}" == "" ]; then
exit 3
fi
if [ ! -f "${1}" ]; then
echo "File does not exist! ${1}"
exit 4
fi
function cleanup() {
if [ -f ${MERGED_TMP_FILE} ]; then
rm ${MERGED_TMP_FILE}
fi
}
trap cleanup EXIT
cleanup
if [[ ${1} == *.osm.pbf ]]; then
# Import a PBF file.
nice -n 18 osm2pgsql -d gis --append --slim -G --hstore --tag-transform-script \
/opt/openstreetmap-carto/openstreetmap-carto.lua -C 2000 --number-processes 3 \
-S /opt/openstreetmap-carto/openstreetmap-carto.style "${1}"
# Import PBF files.
for i in "$@"; do
if [[ $i != *.osm.pbf ]]; then
echo "Cannot mix file types"
exit 5
fi
if [ ! -f "${i}" ]; then
echo "File does not exist! ${i}"
exit 6
fi
done
# Use 1/4 of the RAM to import. 1/2 causes crashes on RPi.
RAM_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}')
MAX_CACHE=$((RAM_KB / 1024 / 4))
pbf_path=${1}
pbf_paths=($@)
if [[ ${#pbf_paths[@]} -gt 1 ]]; then
# More than one PBF, merge them before import.
nice -n 18 osmium merge $@ -o ${MERGED_TMP_FILE}
pbf_path=${MERGED_TMP_FILE}
fi
nice -n 18 osm2pgsql -d gis --create --slim -G --hstore \
--tag-transform-script /opt/openstreetmap-carto/openstreetmap-carto.lua \
-C ${MAX_CACHE} \
--number-processes 3 \
-S /opt/openstreetmap-carto/openstreetmap-carto.style \
"${pbf_path}"
elif [[ ${1} == *.dump ]]; then
if [ ! -f "${1}" ]; then
echo "File does not exist! ${1}"
exit 4
fi
# Import a Postgresql dump.
nice -n 18 pg_restore -j3 --no-owner -d gis "${1}"
else
echo "Cannot import unknown map file"
exit 5
exit 7
fi

View file

@ -9,7 +9,7 @@ set -e
[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mtime -1)" ] && apt update
# Install map dependencies.
apt install -y libapache2-mod-tile renderd tar unzip wget bzip2 apache2 lua5.1 mapnik-utils python3-mapnik gdal-bin \
fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted ttf-unifont
fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted ttf-unifont osmium-tool
/usr/bin/npm install -g carto
/usr/local/bin/carto -v

View file

@ -13,7 +13,7 @@ apt install -y libboost-all-dev git tar unzip wget bzip2 build-essential autocon
libicu-dev libgdal-dev libcairo2-dev libcairomm-1.0-dev libagg-dev liblua5.2-dev ttf-unifont lua5.1 liblua5.1-0-dev \
postgis postgresql-12-postgis-3 postgresql-12-postgis-3-scripts osm2pgsql gdal-bin libmapnik-dev mapnik-utils \
python3-mapnik apache2 apache2-dev libcurl4-gnutls-dev libiniparser-dev libmemcached-dev librados-dev \
fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted postgresql-contrib
fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted postgresql-contrib osmium-tool
/usr/bin/npm install -g carto
/usr/bin/carto -v