Skip to content

Instantly share code, notes, and snippets.

@cquest
Last active January 4, 2018 10:39
Show Gist options
  • Save cquest/5ace436a43c311ec1e7b040216a1cf82 to your computer and use it in GitHub Desktop.
Save cquest/5ace436a43c311ec1e7b040216a1cf82 to your computer and use it in GitHub Desktop.
Export découpages administratifs 2018 d'OpenStreetMap pour data.gouv.fr
export SHAPE_ENCODING="UTF-8"
pushd /home/cquest/public_html/openfla/export/
# export communes (métropole et DOM)
ogr2ogr -f "ESRI Shapefile" -lco ENCODING=UTF-8 -s_srs "EPSG:3857" -s_srs "EPSG:3857" -t_srs "EPSG:4326" -overwrite communes-20180101.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 fr_admin where tags ? 'ref:INSEE' and admin_level='8' and tags->'ref:INSEE'<'98000' and tags->'ref:INSEE' not like '975%'"
zip -9m communes-20180101-shp.zip communes-20180101.* && zip communes-20180101-shp.zip LICENCE.txt communes-descriptif.txt
# export communes (hors métropole et DOM)
ogr2ogr -f "ESRI Shapefile" -lco ENCODING=UTF-8 -s_srs "EPSG:3857" -t_srs "EPSG:4326" -overwrite communes-com-20180101.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 fr_admin where tags ? 'ref:INSEE' and admin_level='8' and tags->'ref:INSEE'>='98000' and tags->'ref:INSEE' like '975%'"
zip -9m communes-com-20180101-shp.zip communes-com-20180101.* && zip communes-com-20180101-shp.zip LICENCE.txt communes-com-descriptif.txt
# export arrondissements municipaux
ogr2ogr -f "ESRI Shapefile" -lco ENCODING=UTF-8 -s_srs "EPSG:3857" -t_srs "EPSG:4326" -overwrite arrondissements-municipaux-20180101.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 fr_admin 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-20180101-shp.zip arrondissements-municipaux-20180101.* && zip arrondissements-municipaux-20180101-shp.zip LICENCE.txt arrondissements-municipaux-descriptif.txt
# export communes fusionnées
ogr2ogr -f "ESRI Shapefile" -lco ENCODING=UTF-8 -s_srs "EPSG:3857" -t_srs "EPSG:4326" -overwrite communes-anciennes-20180101.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, tags->'start_date' as debut, tags->'end_date' as fin, tags->'admin_type:FR' as status, way from fr_admin 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 communes-anciennes-20180101-shp.zip communes-anciennes-20180101.* && zip communes-anciennes-20180101-shp.zip LICENCE.txt communes-anciennes-descriptif.txt
# export départements (métropole et DOM)
ogr2ogr -f "ESRI Shapefile" -lco ENCODING=UTF-8 -s_srs "EPSG:3857" -t_srs "EPSG:4326" -overwrite departements-20180101.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 fr_admin where tags ? 'ref:INSEE' and admin_level='6' and tags->'ref:INSEE'<'98000' and tags->'ref:INSEE' not like '975%'"
zip -9m departements-20180101-shp.zip departements-20180101.* && zip departements-20180101-shp.zip LICENCE.txt departements-descriptif.txt
# export régions (métropole et DOM)
ogr2ogr -f "ESRI Shapefile" -lco ENCODING=UTF-8 -s_srs "EPSG:3857" -t_srs "EPSG:4326" -overwrite regions-20180101.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 fr_admin where tags ? 'ref:INSEE' and admin_level='4'"
zip -9m regions-20180101-shp.zip regions-20180101.* && zip regions-20180101-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