-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.sh
85 lines (68 loc) · 2.8 KB
/
import.sh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "${SCRIPT_DIR}/setenv.sh" || {
exit 1
}
#--------------------------------------------------------------
# Handle import / update options
#--------------------------------------------------------------
PGDATABASE=${PGDATABASE:-osm}
echo "[INFO] PGDATABASE=${PGDATABASE}"
echo "[DEBUG] OSM2PGSQL_OPTS=${OSM2PGSQL_OPTS}"
#--------------------------------------------------------------
# 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}"
FORCE_DOWNLOAD=${FORCE_DOWNLOAD:-0}
echo "[INFO] FORCE_DOWNLOAD=${FORCE_DOWNLOAD}"
CREATE_DB=${CREATE_DB:-1}
echo "[INFO] CREATE_DB=${CREATE_DB}"
#--------------------------------------------------------------
# Create osm database
#--------------------------------------------------------------
if [ "$CREATE_DB" != "0" ];
then
createdb "$PGDATABASE"
psql -d "$PGDATABASE" -c "CREATE EXTENSION IF NOT EXISTS postgis"
psql -d "$PGDATABASE" -c "CREATE EXTENSION IF NOT EXISTS hstore"
fi
#--------------------------------------------------------------
# Download external data
#--------------------------------------------------------------
cd "${OSM_CARTO_DIR}"
python3 "scripts/get-external-data.py" \
--database $PGDATABASE \
--verbose
#--------------------------------------------------------------
# Download OSM data
#--------------------------------------------------------------
mkdir -p "$OSM_DATA_DIR"
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
# --flat-nodes="${OSM_DATA_DIR}/nodes.raw" --cache=0
#--------------------------------------------------------------
osm2pgsql \
--database=$PGDATABASE \
${OSM2PGSQL_OPTS} \
--style="${OSM_CARTO_DIR}/openstreetmap-carto.style" \
--tag-transform-script="${OSM_CARTO_DIR}/openstreetmap-carto.lua" \
"$OSM_DATA_DIR/osm.pbf"
#--------------------------------------------------------------
# Init replication table
#--------------------------------------------------------------
osm2pgsql-replication init \
--database=$PGDATABASE \
--osm-file "$OSM_DATA_DIR/osm.pbf"
#--------------------------------------------------------------
# Create indexes
#--------------------------------------------------------------
python3 "${OSM_CARTO_DIR}/scripts/indexes.py"