ar_redadeg/scripts/load_communes_osm_fr.sh

46 lines
1.3 KiB
Bash
Raw Normal View History

2020-02-15 12:33:20 +00:00
#!/bin/bash
set -e
set -u
2021-03-10 07:57:08 +00:00
millesime=2022
2020-02-15 12:33:20 +00:00
PSQL=/usr/bin/psql
DB_HOST=localhost
2021-03-10 07:57:08 +00:00
DB_NAME=redadeg_$millesime
2020-02-15 12:33:20 +00:00
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
2021-03-10 07:57:08 +00:00
mkdir -p ../data/$millesime/
cd ../data/$millesime/
2020-02-15 12:33:20 +00:00
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/
2021-03-10 07:57:08 +00:00
#curl -sS http://osm13.openstreetmap.fr/~cquest/openfla/export/communes-20210101-shp.zip > communes-20210101-shp.zip
wget http://osm13.openstreetmap.fr/~cquest/openfla/export/communes-20210101-shp.zip
2019-09-19 19:00:42 +00:00
2021-03-10 00:07:38 +00:00
unzip -o communes-20210101-shp.zip
2019-09-19 19:00:42 +00:00
2021-03-10 00:07:38 +00:00
ogr2ogr -f "PostgreSQL" PG:"host=$DB_HOST user=$DB_USER password=$DB_PASSWD dbname=$DB_NAME" communes-20210101.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