This repository has been archived by the owner on Mar 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-shapefiles.sh
executable file
·84 lines (71 loc) · 2.61 KB
/
get-shapefiles.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
#!/usr/bin/env bash
set -e -u
UNZIP_OPTS=-qqun
PSQL="psql -Xq -v ON_ERROR_STOP=1"
schema=shapefile_load
# create and populate data dir
mkdir -p data/
$PSQL -f - <<EOF
DROP SCHEMA IF EXISTS $schema CASCADE;
CREATE SCHEMA $schema;
EOF
# world_boundaries
# simplified-water-polygons-complete-3857
download="data/simplified-water-polygons-complete-3857.zip"
table=simplified_ocean
# Write the md5sum to a file. If the file doesn't exist, it writes a blank
md5sum "$download" > "$download.md5" || true
echo "downloading simplified-water-polygons-complete-3857..."
curl -z "$download" -L -o "$download" "http://data.openstreetmapdata.com/simplified-water-polygons-complete-3857.zip"
# Check if the file has changed
if md5sum --status -c "$download.md5"
then
echo "$download unchanged"
else
echo "Loading $download"
unzip $UNZIP_OPTS $download \
simplified-water-polygons-complete-3857/simplified_water_polygons.shp \
simplified-water-polygons-complete-3857/simplified_water_polygons.shx \
simplified-water-polygons-complete-3857/simplified_water_polygons.prj \
simplified-water-polygons-complete-3857/simplified_water_polygons.dbf \
simplified-water-polygons-complete-3857/simplified_water_polygons.cpg \
-d data/
shp2pgsql -D -I -c -g "way" -S -s 3857 data/simplified-water-polygons-complete-3857/simplified_water_polygons.shp $schema.$table \
| $PSQL -f -
$PSQL -f - <<EOF
SET client_min_messages = WARNING;
BEGIN;
DROP TABLE IF EXISTS public.$table;
ALTER TABLE $schema.$table SET SCHEMA public;
COMMIT;
EOF
fi
download="data/water-polygons-split-3857.zip"
table=ocean
# Write the md5sum to a file. If the file doesn't exist, it writes a blank
md5sum "$download" > "$download.md5" || true
echo "downloading simplified-water-polygons-complete-3857..."
curl -z "$download" -L -o "$download" "http://data.openstreetmapdata.com/water-polygons-split-3857.zip"
# Check if the file has changed
if md5sum --status -c "$download.md5"
then
echo "$download unchanged"
else
echo "Loading $download"
unzip $UNZIP_OPTS $download \
water-polygons-split-3857/water_polygons.shp \
water-polygons-split-3857/water_polygons.shx \
water-polygons-split-3857/water_polygons.prj \
water-polygons-split-3857/water_polygons.dbf \
water-polygons-split-3857/water_polygons.cpg \
-d data/
shp2pgsql -D -I -c -g "way" -S -s 3857 data/water-polygons-split-3857/water_polygons.shp $schema.$table \
| $PSQL -f -
$PSQL -f - <<EOF
SET client_min_messages = WARNING;
BEGIN;
DROP TABLE IF EXISTS public.$table;
ALTER TABLE $schema.$table SET SCHEMA public;
COMMIT;
EOF
fi