forked from openmaptiles/openmaptiles-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import-osm
executable file
·64 lines (56 loc) · 2.04 KB
/
import-osm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
# For backward compatibility, allow both PG* and POSTGRES_* forms,
# with the non-standard POSTGRES_* form taking precedence.
# An error will be raised if neither form is given, except for the PGPORT
export PGHOST="${POSTGRES_HOST:-${PGHOST?}}"
export PGDATABASE="${POSTGRES_DB:-${PGDATABASE?}}"
export PGUSER="${POSTGRES_USER:-${PGUSER?}}"
export PGPASSWORD="${POSTGRES_PASSWORD:-${PGPASSWORD?}}"
export PGPORT="${POSTGRES_PORT:-${PGPORT:-5432}}"
: "${DIFF_MODE:=true}"
function import_pbf() {
local pbf_file="$1"
local diff_flag=""
if [ "$DIFF_MODE" = true ]; then
diff_flag="-diff"
echo "Importing $pbf_file into $PGHOST:$PGPORT/$PGDATABASE using Imposm in DIFF mode..."
else
echo "Importing $pbf_file into $PGHOST:$PGPORT/$PGDATABASE using Imposm in NORMAL mode..."
fi
imposm import \
-connection "postgis://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$PGDATABASE" \
-mapping "${IMPOSM_MAPPING_FILE:?}" \
-overwritecache \
-diffdir "${IMPOSM_DIFF_DIR:?}" \
-cachedir "${IMPOSM_CACHE_DIR:?}" \
-read "$pbf_file" \
-deployproduction \
-write \
$diff_flag \
-config "${IMPOSM_CONFIG_FILE:?}"
}
function import_osm_with_first_pbf() {
if [[ -z "${1:-}" ]]; then
# With no parameters, import the first found PBF file in the $PBF_DATA_DIR
echo "Searching for any *.pbf files in $PBF_DATA_DIR"
if [ "$(ls -A "${PBF_DATA_DIR:?}"/*.pbf 2> /dev/null)" ]; then
local pbf_file
for pbf_file in "$PBF_DATA_DIR"/*.pbf; do
import_pbf "$pbf_file"
break
done
else
echo "No PBF files for import found."
echo "Please mount the $PBF_DATA_DIR volume to a folder containing OSM PBF files,"
echo "or provide PBF file as the first parameter to import-osm"
exit 1
fi
else
echo "Importing provided file $1"
import_pbf "$1"
fi
}
import_osm_with_first_pbf "${1:-}"