forked from martgnz/es-atlas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepublish
141 lines (121 loc) · 4.73 KB
/
prepublish
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
# Set path to installed node modules to run the script without npm
PATH=$PATH:./node_modules/.bin
# Default variables
NDJSONMAP_ARGS="(delete d.properties, d)"
NDJSONFILTER_ARGS='d'
SP=$2
QU=$3
AUTONOMOUS_REGIONS_IDS=$4
if [ "$1" = true ]; then
echo "Adding names to the files"
NDJSONMAP_ARGS="(name = d.properties.NAMEUNIT, delete d.properties, d.properties={}, d.properties.name=name, d)"
fi
if [ "$4" != all ]; then
NDJSONFILTER_ARGS="'${AUTONOMOUS_REGIONS_IDS}'.split(',').includes(d.properties.NATCODE.slice(2, 4))"
# Change default quantization and simplification to have a sharper map
if [ "$2" = 0.0001 ]; then
SP=1e-5
fi
if [ "$3" = 10000 ]; then
QU=1e5
fi
fi
echo "Autonomous regions: $AUTONOMOUS_REGIONS_IDS"
echo "Simplification: $SP"
echo "Quantization: $QU"
rm -rvf es
mkdir -p es
if [ ! -d build ]; then
mkdir build
curl "http://centrodedescargas.cnig.es/CentroDescargas/descargaDir" --compressed --data "secuencialDescDir=9000029&aceptCodsLicsDD_0=15" > build/lineas_limite.zip
unzip -jod build build/lineas_limite.zip recintos_municipales* recintos_provinciales* recintos_autonomicas*
fi
geo2topo -n autonomous_regions=<( \
shp2json --encoding utf8 -n build/recintos_autonomicas_inspire_peninbal_etrs89.shp \
| ndjson-filter "$NDJSONFILTER_ARGS" \
| ndjson-map '(d.id = d.properties.NATCODE.slice(2, 4), d)'
shp2json --encoding utf8 -n build/recintos_autonomicas_inspire_canarias_wgs84.shp \
| ndjson-filter "$NDJSONFILTER_ARGS" \
| ndjson-map '(d.id = d.properties.NATCODE.slice(2, 4), d)') \
| toposimplify -f -p $SP \
| topomerge border=autonomous_regions \
> es/autonomous_regions.json
geo2topo -n provinces=<( \
shp2json --encoding utf8 -n build/recintos_provinciales_inspire_peninbal_etrs89.shp \
| ndjson-filter "$NDJSONFILTER_ARGS" \
| ndjson-map '(d.id = d.properties.NATCODE.slice(4, 6), d)'
shp2json --encoding utf8 -n build/recintos_provinciales_inspire_canarias_wgs84.shp \
| ndjson-filter "$NDJSONFILTER_ARGS" \
| ndjson-map '(d.id = d.properties.NATCODE.slice(4, 6), d)') \
| toposimplify -f -p $SP \
| topomerge autonomous_regions=provinces -k 'd.properties.NATCODE.slice(2, 4)' \
| topomerge border=autonomous_regions \
> es/provinces.json
geo2topo -n municipalities=<( \
shp2json --encoding utf8 -n build/recintos_municipales_inspire_peninbal_etrs89.shp \
| ndjson-filter "$NDJSONFILTER_ARGS" \
| ndjson-map '(d.id = d.properties.NATCODE.slice(6, 11), d)'
shp2json --encoding utf8 -n build/recintos_municipales_inspire_canarias_wgs84.shp \
| ndjson-filter "$NDJSONFILTER_ARGS" \
| ndjson-map '(d.id = d.properties.NATCODE.slice(6, 11), d)') \
| toposimplify -f -p $SP \
| topomerge provinces=municipalities -k 'd.properties.NATCODE.slice(4, 6)' \
| topomerge autonomous_regions=municipalities -k 'd.properties.NATCODE.slice(2, 4)' \
| topomerge border=autonomous_regions \
> es/municipalities.json
# Inspired by: https://bl.ocks.org/mbostock/39b34968ad5eab65de1d7da81f78bb27
# Re-compute the topology as a further optimization.
# This consolidates unique sequences of arcs.
# https://github.com/topojson/topojson-simplify/issues/4
topo2geo -n \
< es/autonomous_regions.json \
autonomous_regions=es/_autonomous_regions.json \
border=es/_border.json
geo2topo -n \
autonomous_regions=<( \
cat es/_autonomous_regions.json \
| ndjson-map "$NDJSONMAP_ARGS") \
border=<( \
cat es/_border.json \
| ndjson-map "$NDJSONMAP_ARGS") \
| topoquantize $QU \
> es/autonomous_regions.json
topo2geo -n \
< es/provinces.json \
provinces=es/_provinces.json
geo2topo -n \
provinces=<( \
cat es/_provinces.json \
| ndjson-map "$NDJSONMAP_ARGS") \
autonomous_regions=<( \
cat es/_autonomous_regions.json \
| ndjson-map "$NDJSONMAP_ARGS") \
border=<( \
cat es/_border.json \
| ndjson-map "$NDJSONMAP_ARGS") \
| topoquantize $QU \
> es/provinces.json
rm es/_provinces.json es/_autonomous_regions.json es/_border.json
topo2geo -n \
< es/municipalities.json \
municipalities=es/_municipalities.json \
provinces=es/_provinces.json \
autonomous_regions=es/_autonomous_regions.json \
border=es/_border.json
geo2topo -n \
municipalities=<( \
cat es/_municipalities.json \
| ndjson-map "$NDJSONMAP_ARGS") \
provinces=<( \
cat es/_provinces.json \
| ndjson-map "$NDJSONMAP_ARGS") \
autonomous_regions=<( \
cat es/_autonomous_regions.json \
| ndjson-map "$NDJSONMAP_ARGS") \
border=<( \
cat es/_border.json \
| ndjson-map "$NDJSONMAP_ARGS") \
| topoquantize $QU \
> es/municipalities.json
rm es/_municipalities.json es/_provinces.json es/_autonomous_regions.json es/_border.json