maj chargement couche des communes
This commit is contained in:
parent
34f24f9095
commit
df65de886c
37
scripts/load_communes.sh
Normal file → Executable file
37
scripts/load_communes.sh
Normal file → Executable file
|
@ -1,33 +1,42 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
PSQL=/usr/bin/psql
|
||||
DB_HOST=localhost
|
||||
DB_NAME=redadeg
|
||||
DB_USER=redadeg
|
||||
DB_PASSWD=redadeg
|
||||
|
||||
# ce script récupère une couche des communes de France et la charge dans la base de données
|
||||
|
||||
cd data
|
||||
|
||||
# récupérer la couche communales OSM
|
||||
# https://www.data.gouv.fr/fr/datasets/decoupage-administratif-communal-francais-issu-d-openstreetmap/
|
||||
wget http://osm13.openstreetmap.fr/~cquest/openfla/export/communes-20190101-shp.zip
|
||||
wget http://osm13.openstreetmap.fr/~cquest/openfla/export/communes-20200101-shp.zip
|
||||
#wget pour voir la progression
|
||||
|
||||
mv communes-20190101-shp.zip data/
|
||||
unzip communes-20190101-shp.zip
|
||||
unzip communes-20200101-shp.zip
|
||||
|
||||
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
|
||||
|
||||
# tansformer le shape en requête insert
|
||||
shp2pgsql -I communes-20190101.shp osm_communes > osm_communes.sql
|
||||
|
||||
# charger
|
||||
psql -d redadeg -U redadeg -W < osm_communes.sql
|
||||
|
||||
# passer la couche de WGS84 en Lambert93
|
||||
psql -c "INSERT INTO osm_communes
|
||||
$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
|
||||
SELECT
|
||||
gid,
|
||||
ogc_fid,
|
||||
insee,
|
||||
nom,
|
||||
wikipedia,
|
||||
surf_ha,
|
||||
ST_Transform(ST_SetSRID(geom,4326),2154) AS the_geom
|
||||
ST_Transform(ST_SetSRID(the_geom,4326),2154) AS the_geom
|
||||
FROM osm_communes_4326
|
||||
WHERE left(insee,2) IN ('22','29','35','44','56')
|
||||
ORDER BY insee ASC ;"
|
||||
$PSQL -h $DB_HOST -U $DB_USER -d $DB_NAME -c "VACUUM FULL osm_communes;"
|
||||
|
||||
|
||||
# /!\ penser à ne garder que les communes nécessaires pour des questions de performance
|
||||
|
||||
|
|
Loading…
Reference in a new issue