forked from openmaptiles/openmaptiles-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-tiles
executable file
·74 lines (64 loc) · 2.61 KB
/
generate-tiles
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
#!/bin/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 PGDATABASE="${POSTGRES_DB:-${PGDATABASE?}}"
export PGUSER="${POSTGRES_USER:-${PGUSER?}}"
export PGPASSWORD="${POSTGRES_PASSWORD:-${PGPASSWORD?}}"
export PGPORT="${POSTGRES_PORT:-${PGPORT:-5432}}"
# List of postgres servers
# "xxx.xxx.xxx.xxx&host=xxx.xxx.xxx.xxx&host=..."
if [[ -z "${PGHOSTS_LIST}" ]]
then
export HOST_COUNT=1
export PGHOSTS="${POSTGRES_HOST:-${PGHOST?}}"
else
export HOST_COUNT=`awk -F"&" '{print NF}' <<< "${PGHOSTS_LIST}"`
export PGHOSTS="${PGHOSTS_LIST}"
fi
if [[ -n "${NO_GZIP:-}" ]] && [[ "${NO_GZIP:-}" != "0" ]] && [[ "${NO_GZIP:-}" != "false" ]]; then
export NO_GZIP="&nogzip=1"
else
export NO_GZIP=
fi
if [[ -n "${USE_KEY_COLUMN:-}" ]] && [[ "${USE_KEY_COLUMN:-}" != "0" ]] && [[ "${USE_KEY_COLUMN:-}" != "false" ]]; then
export USE_KEY_COLUMN="&key=1"
else
export USE_KEY_COLUMN=
fi
if [[ -n "${TEST_ON_STARTUP:-}" ]] && [[ "${TEST_ON_STARTUP:-}" != "0" ]] && [[ "${TEST_ON_STARTUP:-}" != "false" ]]; then
export TEST_ON_STARTUP_TILE="&testOnStartup=${TEST_ON_STARTUP}"
else
export TEST_ON_STARTUP_TILE=
fi
export FUNC_ZXY=${FUNC_ZXY:-getmvt}
export COPY_CONCURRENCY=${COPY_CONCURRENCY:-1} # number of CPUs per postgres server
export MAX_HOST_CONNECTIONS=${MAX_HOST_CONNECTIONS:-${COPY_CONCURRENCY}}
export ALL_STREAMS=$(( MAX_HOST_CONNECTIONS * HOST_COUNT ))
export EXPORT_DIR=${EXPORT_DIR:-/export}
export MBTILES_FILE=${MBTILES_FILE:-tiles.mbtiles}
export RENDER_SCHEME=${RENDER_SCHEME:-pyramid}
export RETRY=${RETRY:-2}
export BBOX=${BBOX:-"-180.0,-85.0511,180.0,85.0511"}
export TIMEOUT=${TIMEOUT:-1800000}
export MIN_ZOOM=${MIN_ZOOM:-0}
export MAX_ZOOM=${MAX_ZOOM:-14}
export PGQUERY="pgquery://?database=${PGDATABASE}&host=${PGHOSTS}&port=${PGPORT}&username=${PGUSER}&password=${PGPASSWORD}&funcZXY=${FUNC_ZXY}&maxpool=${MAX_HOST_CONNECTIONS}${NO_GZIP}${USE_KEY_COLUMN}${TEST_ON_STARTUP_TILE}"
echo $PGQUERY
function export_local_mbtiles() {
exec tilelive-copy \
--scheme="$RENDER_SCHEME" \
--retry="$RETRY" \
--bounds="$BBOX" \
--timeout="$TIMEOUT" \
--minzoom="$MIN_ZOOM" \
--maxzoom="$MAX_ZOOM" \
--concurrency="$ALL_STREAMS" \
"$PGQUERY" \
"mbtiles://${EXPORT_DIR}/${MBTILES_FILE}"
}
echo "Generating zoom $MIN_ZOOM..$MAX_ZOOM from $HOST_COUNT servers, using $MAX_HOST_CONNECTIONS connections per server, $ALL_STREAMS parallel streams..."
export_local_mbtiles