Skip to content

Instantly share code, notes, and snippets.

@cquest
Last active February 18, 2019 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cquest/86e62bb6ed832d461671dee0ebe72244 to your computer and use it in GitHub Desktop.
Save cquest/86e62bb6ed832d461671dee0ebe72244 to your computer and use it in GitHub Desktop.
Export limites admin OSM 2019
export SHAPE_ENCODING="UTF-8"
pushd /home/cquest/public_html/openfla/export/
yymmdd=$(date +%Y%m%d)
# export communes (métropole et DOM)
ogr2ogr -f "ESRI Shapefile" -lco ENCODING=UTF-8 -t_srs "EPSG:4326" -overwrite communes-$yymmdd.shp PG:"dbname=osm" -sql "select tags->'ref:INSEE' as insee, name as nom, tags->'wikipedia' as wikipedia, floor(st_area(geography(st_transform(way,4326)))/10000) as surf_ha, way from osm_admin_fr where tags ? 'ref:INSEE' and admin_level='8' and tags->'ref:INSEE'<'98000' and tags->'ref:INSEE' not like '975%'"
zip -9m communes-$yymmdd-shp.zip communes-$yymmdd.* && zip communes-$yymmdd-shp.zip LICENCE.txt communes-descriptif.txt
# export communes (hors métropole et DOM)
ogr2ogr -f "ESRI Shapefile" -lco ENCODING=UTF-8 -t_srs "EPSG:4326" -overwrite communes-com-$yymmdd.shp PG:"dbname=osm" -sql "select tags->'ref:INSEE' as insee, name as nom, tags->'wikipedia' as wikipedia, floor(st_area(geography(st_transform(way,4326)))/10000) as surf_ha, way from osm_admin_fr where tags ? 'ref:INSEE' and admin_level='8' and tags->'ref:INSEE'>='98000' and tags->'ref:INSEE' like '975%'"
zip -9m communes-com-$yymmdd-shp.zip communes-com-$yymmdd.* && zip communes-com-$yymmdd-shp.zip LICENCE.txt communes-com-descriptif.txt
# export arrondissements municipaux
ogr2ogr -f "ESRI Shapefile" -lco ENCODING=UTF-8 -t_srs "EPSG:4326" -overwrite arrondissements-municipaux-$yymmdd.shp PG:"dbname=osm" -sql "select tags->'ref:INSEE' as insee, name as nom, tags->'wikipedia' as wikipedia, floor(st_area(geography(st_transform(way,4326)))/10000) as surf_ha, way from osm_admin_fr where tags ? 'ref:INSEE' and admin_level='9' and tags->'admin_type:FR' = 'arrondissement municipal' and tags->'ref:INSEE'>='98000' and tags->'ref:INSEE' like '975%'"
zip -9m arrondissements-municipaux-$yymmdd-shp.zip arrondissements-municipaux-$yymmdd.* && zip arrondissements-municipaux-$yymmdd-shp.zip LICENCE.txt arrondissements-municipaux-descriptif.txt
# export communes fusionnées
ogr2ogr -f "ESRI Shapefile" -lco ENCODING=UTF-8 -t_srs "EPSG:4326" -overwrite communes-anciennes-$yymmdd.shp PG:"dbname=osm" -sql "select way, tags->'ref:INSEE' as insee, name as nom, tags->'wikipedia' as wikipedia, floor(st_area(geography(st_transform(way,4326)))/10000) as surf_ha, tags->'start_date' as debut, tags->'end_date' as fin, tags->'admin_type:FR' as status from osm_admin_fr where tags ? 'ref:INSEE' and admin_level='9' and tags->'admin_type:FR' != 'arrondissement municipal' and tags->'ref:INSEE'<'98000' and tags->'ref:INSEE' not like '975%'"
zip -9m communes-anciennes-$yymmdd-shp.zip communes-anciennes-$yymmdd.* && zip communes-anciennes-$yymmdd-shp.zip LICENCE.txt communes-anciennes-descriptif.txt
# export départements (métropole et DOM)
ogr2ogr -f "ESRI Shapefile" -lco ENCODING=UTF-8 -t_srs "EPSG:4326" -overwrite departements-$yymmdd.shp PG:"dbname=osm" -sql "select tags->'ref:INSEE' as code_insee, name as nom, tags->'ref:NUTS' as nuts3, tags->'wikipedia' as wikipedia, floor(st_area(geography(st_transform(way,4326)))/1000000) as surf_km2, way from osm_admin_fr where tags ? 'ref:INSEE' and admin_level='6' and tags->'ref:INSEE'<'98000' and tags->'ref:INSEE' not like '975%'"
zip -9m departements-$yymmdd-shp.zip departements-$yymmdd.* && zip departements-$yymmdd-shp.zip LICENCE.txt departements-descriptif.txt
# export régions (métropole et DOM)
ogr2ogr -f "ESRI Shapefile" -lco ENCODING=UTF-8 -t_srs "EPSG:4326" -overwrite regions-$yymmdd.shp PG:"dbname=osm" -sql "select tags->'ref:INSEE' as code_insee, name as nom, tags->'ref:NUTS' as nuts2, tags->'wikipedia' as wikipedia, floor(st_area(geography(st_transform(way,4326)))/1000000) as surf_km2, way from osm_admin_fr where tags ? 'ref:INSEE' and admin_level='4'"
zip -9m regions-$yymmdd-shp.zip regions-$yymmdd.* && zip regions-$yymmdd-shp.zip LICENCE.txt regions-descriptif.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment