Skip to content

Commit c678a36

Browse files
chore: reworked admin-express with french polynesia integration
1 parent 0544fb5 commit c678a36

3 files changed

Lines changed: 69 additions & 133 deletions

File tree

fetch-polynesia.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
POLYNESIA_DIR="$1"
5+
ADMIN_EXPRESS_DIR="$2"
6+
TMPDIR="tmp/$1"
7+
8+
mkdir -p "$TMPDIR" "$POLYNESIA_DIR"
9+
10+
# Données issues de https://www.data.gouv.fr/fr/datasets/limites-geographiques-administratives/
11+
# Code INSEE issus de https://www.tefenua.data.gov.pf/maps/6e392df616c949309eda19656450562a/about (couche ISPF_Codes_INSEE)
12+
13+
wget -O "$TMPDIR/shapefiles.zip" "https://www.data.gouv.fr/fr/datasets/r/211bb006-aba5-475f-a40b-53b42ae765a2"
14+
wget -O "$TMPDIR/ISPF_Codes_INSEE.csv" "https://hub.arcgis.com/api/v3/datasets/6e392df616c949309eda19656450562a_6/downloads/data?format=csv&spatialRefId=3857&where=1%3D1"
15+
16+
7z x -y "$TMPDIR/shapefiles.zip" -o"$TMPDIR/shapefiles"
17+
18+
# 1. Patch some commune names that don't match the one in ISPF_Codes_INSEE
19+
# 2. Merge with INSEE code
20+
# 3. Rename properties to match admin-express
21+
# 4. Add INSEE_DEP to match admin-express
22+
# 5. Remove original properties
23+
# 6. Reproject to WGS84
24+
mapshaper "$TMPDIR/shapefiles/Com.shp" \
25+
-each 'Commune = "Bora-Bora"' where='Commune == "Bora Bora"' \
26+
-each 'Commune = "Faaa"' where="Commune == \"Faa'a\"" \
27+
-each 'Commune = "Fatu-Hiva"' where='Commune == "Fatu Hiva"' \
28+
-each 'Commune = "Hiva-Oa"' where='Commune == "Hiva Oa"' \
29+
-each 'Commune = "Nuku-Hiva"' where='Commune == "Nuku Hiva"' \
30+
-each 'Commune = "Ua-Huka"' where='Commune == "Ua Huka"' \
31+
-each 'Commune = "Ua-Pou"' where='Commune == "Ua Pou"' \
32+
-join "$TMPDIR/ISPF_Codes_INSEE.csv" keys=Commune,Communes fields=Code_INSEE_complet string-fields=Code_INSEE_complet \
33+
-rename-fields INSEE_COM=Code_INSEE_complet,NOM=Commune,POPULATION=Indivds \
34+
-each 'INSEE_DEP = "987", NOM_M = NOM.toUpperCase()' \
35+
-filter-fields INSEE_COM,INSEE_DEP,NOM,NOM_M,POPULATION \
36+
-proj wgs84 \
37+
-simplify "80%" \
38+
-o "$POLYNESIA_DIR/COMMUNE.shp"
39+
40+
# Generate departement
41+
# Simplify geometry in the process
42+
mapshaper "$POLYNESIA_DIR/COMMUNE.shp" \
43+
-dissolve copy-fields="" calc='NOM = "Polynésie française", NOM_M = "POLYNÉSIE FRANÇAISE", INSEE_DEP = "987"' \
44+
-simplify "50%" \
45+
-o "$POLYNESIA_DIR/DEPARTEMENT.shp"
46+
47+
# Merge with admin-express
48+
for LAYER in COMMUNE DEPARTEMENT; do
49+
ADMIN_EXPRESS_FILE=$(find "$ADMIN_EXPRESS_DIR" -name "$LAYER.shp")
50+
ADMIN_EXPRESS_DIRNAME=$(dirname "$ADMIN_EXPRESS_FILE")
51+
52+
for EXT in cpg dbf prj shp shx; do
53+
mv "$ADMIN_EXPRESS_DIRNAME/$LAYER.$EXT" "$ADMIN_EXPRESS_DIRNAME/${LAYER}_src.$EXT"
54+
done
55+
56+
mapshaper -i "$ADMIN_EXPRESS_DIRNAME/${LAYER}_src.shp" "$POLYNESIA_DIR/$LAYER.shp" combine-files -merge-layers force -o "$ADMIN_EXPRESS_DIRNAME/$LAYER.shp"
57+
58+
for EXT in cpg dbf prj shp shx; do
59+
rm "$ADMIN_EXPRESS_DIRNAME/${LAYER}_src.$EXT"
60+
done
61+
done

generate-admin-express-mbtiles-with-french-polynesia.sh

Lines changed: 0 additions & 131 deletions
This file was deleted.

jobfile-admin-express.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,15 @@ export default {
178178
{ geometry: '2dsphere', 'properties.layer': 1 }
179179
]
180180
},
181-
runCommand: {
181+
fetchAdminExpress: {
182+
hook: 'runCommand',
182183
command: './geoservices.sh ' + url + ' admin-express'
183184
},
185+
// Fetch and merge french polynesia data with admin-express
186+
fetchAndMergePolynesia: {
187+
hook: 'runCommand',
188+
command: './fetch-polynesia.sh polynesia admin-express'
189+
},
184190
generateTasks: {}
185191
},
186192
after: {
@@ -197,4 +203,4 @@ export default {
197203
}
198204
}
199205
}
200-
}
206+
}

0 commit comments

Comments
 (0)