This repository has been archived by the owner on Jan 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathimport-water.sh
executable file
·60 lines (48 loc) · 1.82 KB
/
import-water.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
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
readonly WATER_POLYGONS_FILE="$IMPORT_DATA_DIR/water_polygons.shp"
function exec_psql() {
PGPASSWORD=$POSTGRES_PASSWORD psql --host="$POSTGRES_HOST" --port="$POSTGRES_PORT" --dbname="$POSTGRES_DB" --username="$POSTGRES_USER"
}
function import_shp() {
local shp_file=$1
local table_name=$2
shp2pgsql -s 3857 -I -g geometry "$shp_file" "$table_name" | exec_psql | hide_inserts
}
function hide_inserts() {
grep -v "INSERT 0 1"
}
function drop_table() {
local table=$1
local drop_command="DROP TABLE IF EXISTS $table;"
echo "$drop_command" | exec_psql
}
function generalize_water() {
local target_table_name="$1"
local source_table_name="$2"
local tolerance="$3"
echo "Generalize $target_table_name with tolerance $tolerance from $source_table_name"
echo "CREATE TABLE $target_table_name AS SELECT ST_Simplify(geometry, $tolerance) AS geometry FROM $source_table_name" | exec_psql
echo "CREATE INDEX ON $target_table_name USING gist (geometry)" | exec_psql
echo "ANALYZE $target_table_name" | exec_psql
}
function import_water() {
local table_name="osm_ocean_polygon"
drop_table "$table_name"
import_shp "$WATER_POLYGONS_FILE" "$table_name"
local gen1_table_name="osm_ocean_polygon_gen1"
drop_table "$gen1_table_name"
generalize_water "$gen1_table_name" "$table_name" 20
local gen2_table_name="osm_ocean_polygon_gen2"
drop_table "$gen2_table_name"
generalize_water "$gen2_table_name" "$table_name" 40
local gen3_table_name="osm_ocean_polygon_gen3"
drop_table "$gen3_table_name"
generalize_water "$gen3_table_name" "$table_name" 80
local gen4_table_name="osm_ocean_polygon_gen4"
drop_table "$gen4_table_name"
generalize_water "$gen4_table_name" "$table_name" 160
}
import_water