2020-02-15 12:33:20 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
|
|
|
|
PSQL=/usr/bin/psql
|
|
|
|
DB_HOST=localhost
|
|
|
|
DB_NAME=redadeg
|
|
|
|
DB_USER=redadeg
|
|
|
|
DB_PASSWD=redadeg
|
2019-09-19 19:00:42 +00:00
|
|
|
|
|
|
|
# ce script récupère une couche des communes de France et la charge dans la base de données
|
|
|
|
|
2020-02-15 12:33:20 +00:00
|
|
|
cd data
|
|
|
|
|
2019-09-19 19:00:42 +00:00
|
|
|
# récupérer la couche communales OSM
|
|
|
|
# https://www.data.gouv.fr/fr/datasets/decoupage-administratif-communal-francais-issu-d-openstreetmap/
|
2020-02-15 12:33:20 +00:00
|
|
|
wget http://osm13.openstreetmap.fr/~cquest/openfla/export/communes-20200101-shp.zip
|
|
|
|
#wget pour voir la progression
|
2019-09-19 19:00:42 +00:00
|
|
|
|
2020-02-15 12:33:20 +00:00
|
|
|
unzip communes-20200101-shp.zip
|
2019-09-19 19:00:42 +00:00
|
|
|
|
2020-02-15 12:33:20 +00:00
|
|
|
ogr2ogr -f "PostgreSQL" PG:"host=$DB_HOST user=$DB_USER password=$DB_PASSWD dbname=$DB_NAME" communes-20200101.shp -nln osm_communes_4326 -lco GEOMETRY_NAME=the_geom -explodecollections -overwrite
|
2019-09-19 19:00:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
# passer la couche de WGS84 en Lambert93
|
2020-02-15 12:33:20 +00:00
|
|
|
$PSQL -h $DB_HOST -U $DB_USER -d $DB_NAME -c "TRUNCATE TABLE osm_communes ;"
|
|
|
|
$PSQL -h $DB_HOST -U $DB_USER -d $DB_NAME -c "
|
|
|
|
INSERT INTO osm_communes
|
2019-09-19 19:00:42 +00:00
|
|
|
SELECT
|
2020-02-15 12:33:20 +00:00
|
|
|
ogc_fid,
|
2019-09-19 19:00:42 +00:00
|
|
|
insee,
|
|
|
|
nom,
|
|
|
|
wikipedia,
|
2020-02-15 12:33:20 +00:00
|
|
|
surf_ha,
|
|
|
|
ST_Transform(ST_SetSRID(the_geom,4326),2154) AS the_geom
|
2019-09-19 19:00:42 +00:00
|
|
|
FROM osm_communes_4326
|
2020-02-15 12:33:20 +00:00
|
|
|
WHERE left(insee,2) IN ('22','29','35','44','56')
|
2019-09-19 19:00:42 +00:00
|
|
|
ORDER BY insee ASC ;"
|
2020-02-15 12:33:20 +00:00
|
|
|
$PSQL -h $DB_HOST -U $DB_USER -d $DB_NAME -c "VACUUM FULL osm_communes;"
|
2019-09-19 19:00:42 +00:00
|
|
|
|
|
|
|
|