Skip to main content
100%

Compiler un EPT (établissements publics territoriaux)/des EPT

✓ Published0🌍 Public
TThomasG77
Last edited Sep 26, 2023
Created on Sep 26, 2023

This example generates GeoJSON files for the Établissements Publics Territoriaux (EPT) of the Greater Paris metropolis. It shows two outputs: a single EPT boundary dissolved from its constituent communes, and a comprehensive file covering all EPTs. The single-EPT workflow uses a bash script with `wget` to fetch commune geometries from the geo.api.gouv.fr API, then applies `jq` to merge them and `mapshaper` with the `-dissolve` operation. The generalized version uses Python with `urllib`, `pandas`, and `geopandas` to read an INSEE Excel spreadsheet, join commune codes to geometries from Etalab’s contours-administratifs dataset, and dissolve by EPT attributes.

AI-generated description

Compiler un EPT (établissements publics territoriaux)/des EPT

Les établissements publics territoriaux (EPT) sont parmis les "EPCI sans fiscalité propre".

Source des données

Fichiers résultats

"One-shot" pour un EPT en bash, avec mapshaper, jq et wget installé

list_insee=$(echo "94017
94015
94018
94033
94042
94058
94046
94052
94067
94068
94069
94079
94080
")

for i in $list_insee;
  do wget -O commune-${i}.geojson "https://geo.api.gouv.fr/communes/$i?format=geojson&geometry=contour";
done;

jq --slurp '{"type": "FeatureCollection","features": .}' commune-*.geojson >| communes-all.geojson

mapshaper communes-all.geojson -dissolve -o format=geojson geojson-type=FeatureCollection ept-200057941.geojson

Version généralisée à tous les EPT

Utilise Python et les bibliothèques associées Pandas et Geopandas

import urllib
import geopandas as gpd
import pandas as pd

insee_remote_url = "https://www.insee.fr/fr/statistiques/fichier/2510634/ept_au_01-01-2023.xlsx"
insee_filename = insee_remote_url.split('/')[-1]
urllib.request.urlretrieve(insee_remote_url, insee_filename)

from openpyxl.styles.colors import WHITE, RGB
__old_rgb_set__ = RGB.__set__

def __rgb_set_fixed__(self, instance, value):
    try:
        __old_rgb_set__(self, instance, value)
    except ValueError as e:
        if e.args[0] == 'Colors must be aRGB hex values':
            __old_rgb_set__(self, instance, WHITE)  # Change color here

RGB.__set__ = __rgb_set_fixed__

xl = pd.ExcelFile(insee_filename)
xl.sheet_names  # see all sheet names
df_composition_communale = xl.parse("Composition_communale", header=5)
df_composition_communale_short = df_composition_communale[['CODGEO', 'EPT', 'LIBEPT']]
df_composition_communale_short['CODGEO']= df_composition_communale_short['CODGEO'].astype(str)

gdf_communes = gpd.read_file("http://etalab-datasets.geo.data.gouv.fr/contours-administratifs/2023/geojson/communes-5m.geojson")

df_merged = communes.merge(df_composition_communale_short, left_on="code", right_on="CODGEO")
df_merged_short = df_merged[['geometry', 'CODGEO', 'EPT', 'LIBEPT']]
ept_zones = df_merged_short.dissolve(by=['EPT', 'LIBEPT'])
ept_zones.to_file("ept_2023.geojson", driver="GeoJSON")

Similar vizzes