Skip to content

Commit

Permalink
Merge pull request #41 from etalab/ept
Browse files Browse the repository at this point in the history
Support EPT
  • Loading branch information
ThomasG77 committed Sep 27, 2023
2 parents 43a0935 + 6e22b01 commit 30e46c3
Show file tree
Hide file tree
Showing 7 changed files with 1,043 additions and 975 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Données concernant le découpage administratif français, au format JSON.
- Départements
- Régions
- EPCI (à fiscalité propre)
- EPT (Etablissements Publics Territoriaux), sans fiscalité propre (disponible depuis 2023)

## Installation

Expand All @@ -28,6 +29,7 @@ const departements = require('@etalab/decoupage-administratif/data/departements.
const regions = require('@etalab/decoupage-administratif/data/regions.json')
const arrondissements = require('@etalab/decoupage-administratif/data/arrondissements.json')
const epci = require('@etalab/decoupage-administratif/data/epci.json')
const ept = require('@etalab/decoupage-administratif/data/ept.json')
```

### via des URLs
Expand All @@ -39,6 +41,7 @@ Pour la dernière version
- Régions https://unpkg.com/@etalab/decoupage-administratif/data/regions.json
- Arrondissements https://unpkg.com/@etalab/decoupage-administratif/data/arrondissements.json
- EPCI https://unpkg.com/@etalab/decoupage-administratif/data/epci.json
- EPT https://unpkg.com/@etalab/decoupage-administratif/data/ept.json

Il est possible de rajouter une version. Pour les EPCI 2021, par exemple https://unpkg.com/@etalab/decoupage-administratif@1.1.1/data/epci.json (voir le lien millésime et version de packages)

Expand All @@ -48,6 +51,7 @@ Vous avez besoin de données selon une année? Voici un tableau récapitulatif p

| Année | Version du package | NPM | Yarn |
|-------|-------------------------------------------|---------------------------------------------------|----------------------------------------------------|
| 2023 | 3.0.0 | `npm install @etalab/decoupage-administratif@3.0.0` | `yarn install @etalab/decoupage-administratif@3.0.0` |
| 2022 | 2.3.1 | `npm install @etalab/decoupage-administratif@2.3.1` | `yarn install @etalab/decoupage-administratif@2.3.1` |
| 2021 | 1.1.1 | `npm install @etalab/decoupage-administratif@1.1.1` | `yarn install @etalab/decoupage-administratif@1.1.1` |
| 2020 | Non disponible, sauf EPCI 2020 avec 0.8.0 | `npm install @etalab/decoupage-administratif@0.8` | `yarn install @etalab/decoupage-administratif@0.8` |
Expand All @@ -57,6 +61,7 @@ Vous avez besoin de données selon une année? Voici un tableau récapitulatif p

* [Code Officiel Géographique](https://insee.fr/fr/information/2560452) de l'INSEE
* [Liste des EPCI à fiscalité propre](https://www.collectivites-locales.gouv.fr/institutions/liste-et-composition-des-epci-fiscalite-propre) de la DGCL ([url exacte](https://www.collectivites-locales.gouv.fr/files/Accueil/DESL/2023/epcicom2023.xlsx))
* [Liste des EPT (Etablissements Publics Territoriaux)](https://www.insee.fr/fr/information/2510634) avec [l'url exacte du fichier](https://www.insee.fr/fr/statistiques/fichier/2510634/ept_au_01-01-2023.xlsx)
* [Population légale](https://www.insee.fr/fr/statistiques/6683035?sommaire=6683037) de l'INSEE + [population Mayotte INSEE 2017](https://www.insee.fr/fr/statistiques/3291775?sommaire=2120838) + [population COM](https://www.insee.fr/fr/statistiques/6683025?sommaire=6683037)
* [Liste des codes postaux](https://www.data.gouv.fr/fr/datasets/base-officielle-des-codes-postaux/) issue des données La Poste. Antérieurement, sous licence ODBL, maintenant en LO
* [Correspondances communes code SIREN et code INSEE](https://www.banatic.interieur.gouv.fr/V5/fichiers-en-telechargement/fichiers-telech.php) Menu gauche "Table de correspondance code SIREN / Code Insee des communes" ([url exacte](https://www.banatic.interieur.gouv.fr/V5/ressources/documents/document_reference/TableCorrespondanceSirenInsee.zip))
Expand Down
32 changes: 32 additions & 0 deletions build/ept.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const {zipObject, chain} = require('lodash')
const {readSheets} = require('./util')

function formatSiren(siren) {
return String(siren).padStart(9, '0')
}

function formatCodeCommune(codeCommune) {
return String(codeCommune).padStart(5, '0')
}

async function extractEPT(path) {
const sheets = await readSheets(path)
const sheet = sheets.find(sheet => sheet.name === 'Composition_communale')
const [columns, ...rows] = sheet.data.slice(5).filter(line => line.length > 0)
const items = rows.map(row => zipObject(columns, row))
return chain(items)
.groupBy('EPT')
.map(items => {
const [first] = items
return {
code: formatSiren(first.EPT),
nom: first.LIBEPT,
type: 'EPT',
modeFinancement: '',
membres: items.map(item => formatCodeCommune(item.CODGEO))
}
})
.value()
}

module.exports = {extractEPT}
34 changes: 32 additions & 2 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const {join} = require('path')
const {remove} = require('fs-extra')
const {extractEPCI} = require('./epci')
const {extractEPT} = require('./ept')
const {extractSirenInsee} = require('./correspondances-insee-siren-communes')
const {extractPopulation, computeMLPPopulation} = require('./population')
const {getCodesPostaux, computeMLPCodesPostaux} = require('./codes-postaux')
Expand Down Expand Up @@ -60,13 +61,42 @@ async function buildCommunes(regions, departements, arrondissements, population)
communesCOM.forEach(commune => data.push(commune))

await writeData('communes', data)
return data
}

async function buildEPCI() {
const rows = await extractEPCI(getSourceFilePath('epcicom.xlsx'))
await writeData('epci', rows)
}

async function buildEPT(communes, population) {
const rows = await extractEPT(getSourceFilePath('ept.xlsx'))
const inseeCommunesWithEpt = rows.reduce((acc, row) => {
acc = [...acc, ...row.membres]
return acc
}, [])
const communesWithEpt = communes
.filter(commune => inseeCommunesWithEpt.includes(commune.code))
.reduce((acc, curr) => {
acc[curr.code] = curr
return acc
}, {})
rows.forEach(row => {
row.membres = row.membres.map(membre => {
return {
code: communesWithEpt[membre].code,
siren: communesWithEpt[membre].siren,
nom: communesWithEpt[membre].nom,
populationTotale: population[membre].populationTotale,
populationMunicipale: population[membre].populationMunicipale
}
})
row.populationTotale = row.membres.map(membre => membre.populationTotale).reduce((a, b) => a + b, 0)
row.populationMunicipale = row.membres.map(membre => membre.populationMunicipale).reduce((a, b) => a + b, 0)
})
await writeData('ept', rows)
}

async function main() {
await remove(join(__dirname, '..', 'data'))

Expand All @@ -81,12 +111,12 @@ async function main() {
const departements = [...departementsMetroAndDrom, ...departementsCom]
const regionsMetroAndDrom = await extractRegions(getSourceFilePath('regions.csv'))
const regions = [...regionsMetroAndDrom, ...regionsCom]

await buildRegions(regions)
await buildDepartements(departements)
await buildArrondissements(arrondissements)
await buildCommunes(regions, departements, arrondissements, population.communes)
const communes = await buildCommunes(regions, departements, arrondissements, population.communes)
await buildEPCI()
await buildEPT(communes, population.communes)
}

function shouldWarnPopulation(codeCommune) {
Expand Down
3 changes: 2 additions & 1 deletion build/population.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ async function extractPopulation(path) {
const rows = await readCsvFile(path, {separator: ';'})
const refactoredRows = rows.map(commune => ({
codeCommune: `${commune.CODDEP.length === 3 ? commune.CODDEP.slice(0, 2) : commune.CODDEP}${commune.CODCOM}`,
populationMunicipale: Number(commune.PMUN.replace(' ', ''))
populationMunicipale: Number(commune.PMUN.replace(' ', '')),
populationTotale: Number(commune.PTOT.replace(' ', ''))
}))
return {
communes: keyBy(refactoredRows, 'codeCommune')
Expand Down
4 changes: 2 additions & 2 deletions sources/communes.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13098,7 +13098,7 @@ COM,32461,76,32,32D,323,0,VERLUS,Verlus,Verlus,3201,
COM,32462,76,32,32D,321,0,VIC FEZENSAC,Vic-Fezensac,Vic-Fezensac,3208,
COM,32463,76,32,32D,323,0,VIELLA,Viella,Viella,3201,
COM,32464,76,32,32D,323,0,VILLECOMTAL SUR ARROS,Villecomtal-sur-Arros,Villecomtal-sur-Arros,3215,
COM,32465,76,32,32D,321,0,VILLEFRANCHE DASTARAC,Villefranche-dAstarac,Villefranche-dAstarac,3217,
COM,32465,76,32,32D,321,0,VILLEFRANCHE D ASTARAC,Villefranche-d'Astarac,Villefranche-d'Astarac,3217,
COM,32466,76,32,32D,323,0,VIOZAN,Viozan,Viozan,3215,
COM,32467,76,32,32D,321,0,SAINT CAPRAIS,Saint-Caprais,Saint-Caprais,3205,
COM,32468,76,32,32D,323,1,AUSSOS,Aussos,Aussos,3203,
Expand Down Expand Up @@ -20089,7 +20089,7 @@ COM,51453,44,51,51D,511,0,RECY,Recy,Recy,5104,
COM,51454,44,51,51D,513,0,REIMS,Reims,Reims,5199,
COM,51455,44,51,51D,514,0,REIMS LA BRULEE,Reims-la-Brûlée,Reims-la-Brûlée,5120,
COM,51456,44,51,51D,511,0,REMICOURT,Remicourt,Remicourt,5101,
COM,51457,44,51,51D,512,0,COEUR DE LA VALLEE,Coeur-de-la-Vallée,Coeur-de-la-Vallée,5106,
COM,51457,44,51,51D,512,0,COEUR DE LA VALLEE,Cœur-de-la-Vallée,Cœur-de-la-Vallée,5106,
COMD,51457,,,,,0,REUIL,Reuil,Reuil,,51457
COM,51458,44,51,51D,512,0,REUVES,Reuves,Reuves,5121,
COM,51459,44,51,51D,512,0,REVEILLON,Réveillon,Réveillon,5121,
Expand Down
Binary file added sources/ept.xlsx
Binary file not shown.
Loading

0 comments on commit 30e46c3

Please sign in to comment.