Skip to content

Commit

Permalink
Merge pull request #37 from etalab/feature/siren-communes
Browse files Browse the repository at this point in the history
Feature/siren communes
  • Loading branch information
ThomasG77 authored Aug 31, 2022
2 parents 1fa722d + 90356aa commit 472d1ab
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Vous avez besoin de données selon une année? Voici un tableau récapitulatif p
* [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/2022/epcicom2022.xlsx))
* [Population légale](https://www.insee.fr/fr/statistiques/6011070?sommaire=6011075) de l'INSEE + [population Mayotte INSEE 2017](https://www.insee.fr/fr/statistiques/3291775?sommaire=2120838)
* [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))

## Licence

Expand Down
22 changes: 12 additions & 10 deletions build/collectivites-outremer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const {readCsvFile} = require('./util')

const chefLieuCOM = {
'975': '97502',
'977': '97701',
'978': '97801',
'984': '97502',
'986': '98613',
'987': '98735',
'988': '98818',
'989': '98901'
975: '97502',
977: '97701',
978: '97801',
984: '97502',
986: '98613',
987: '98735',
988: '98818',
989: '98901'
}

async function extractCommunesCOM(path) {
Expand Down Expand Up @@ -45,7 +45,7 @@ async function generateDepartementsAndRegionsCOM(path) {

const departements = Object.values(rows.reduce((acc, curr) => {
if (!(curr.code_collectivite in acc)) {
acc[curr.code_collectivite] = {
acc[curr.code_collectivite] = {
code: curr.code_collectivite,
region: curr.code_collectivite,
chefLieu: chefLieuCOM[curr.code_collectivite],
Expand All @@ -54,13 +54,15 @@ async function generateDepartementsAndRegionsCOM(path) {
zone: 'com'
}
}

return acc
}, {}))

const regions = JSON.parse(JSON.stringify(departements)).map(el => {
delete el.region
return el
});
})

return [departements, regions]
}

Expand Down
11 changes: 11 additions & 0 deletions build/correspondances-insee-siren-communes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const {zipObject, keyBy} = require('lodash')
const {readSheets} = require('./util')

async function extractSirenInsee(path) {
const [sheet] = await readSheets(path)
const [columns, ...rows] = sheet.data
const items = rows.map(row => zipObject(columns, row))
return keyBy(items, 'insee')
}

module.exports = {extractSirenInsee}
8 changes: 7 additions & 1 deletion 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 {extractSirenInsee} = require('./correspondances-insee-siren-communes')
const {extractPopulation, computeMLPPopulation} = require('./population')
const {getCodesPostaux, computeMLPCodesPostaux} = require('./codes-postaux')
const {MLP_CODES} = require('./mlp')
Expand All @@ -22,6 +23,7 @@ async function buildArrondissements(arrondissements) {
}

async function buildCommunes(regions, departements, arrondissements, population) {
const inseeSirenMatching = await extractSirenInsee(getSourceFilePath('banatic_siren_insee.xlsx'))
const data = await extractCommunes(
getSourceFilePath('communes.csv'),
getSourceFilePath('mouvements-communes.csv'),
Expand All @@ -32,7 +34,11 @@ async function buildCommunes(regions, departements, arrondissements, population)

data.forEach(commune => {
if (['commune-actuelle', 'arrondissement-municipal'].includes(commune.type)) {
const codesPostaux = getCodesPostaux(commune.code)
if (commune.code in inseeSirenMatching) {
commune.siren = String(inseeSirenMatching[commune.code].siren)
}

const codesPostaux = getCodesPostaux()
if (codesPostaux.length > 0) {
commune.codesPostaux = codesPostaux
} else if (shouldWarnCodePostal(commune.code)) {
Expand Down
Binary file added sources/banatic_siren_insee.xlsx
Binary file not shown.

0 comments on commit 472d1ab

Please sign in to comment.