Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage COM as dept and region, flatten key collectiviteOutremer #35

Merged
merged 5 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions build/cog.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ async function extractDepartements(path) {
const rows = await readCsvFile(path)

return rows.map(row => {
let zone
if (row.ZONE) {
ThomasG77 marked this conversation as resolved.
Show resolved Hide resolved
zone = row.ZONE
} else if (row.DEP.length > 2) {
zone = 'drom'
} else {
zone = 'metro'
}

return {
code: row.DEP,
region: row.REG,
chefLieu: row.CHEFLIEU,
nom: row.LIBELLE,
typeLiaison: parseTypeLiaison(row.TNCC)
typeLiaison: parseTypeLiaison(row.TNCC),
zone
}
})
}
Expand All @@ -23,11 +33,21 @@ async function extractRegions(path) {
const rows = await readCsvFile(path)

return rows.map(row => {
let zone
if (row.ZONE) {
zone = row.ZONE
} else if (['01', '02', '03', '04', '06'].includes(row.REG)) {
zone = 'drom'
} else {
zone = 'metro'
}

return {
code: row.REG,
chefLieu: row.CHEFLIEU,
nom: row.LIBELLE,
typeLiaison: parseTypeLiaison(row.TNCC)
typeLiaison: parseTypeLiaison(row.TNCC),
zone
}
})
}
Expand Down Expand Up @@ -116,10 +136,20 @@ async function extractCommunes(communesPath, mouvementsCommunesPath, arrondissem
const anciensCodesIndex = computeAnciensCodesCommunes(communesRows, mouvementsRows)

const communes = communesRows.map(row => {
let zone
if (row.zone) {
zone = row.zone
} else if (row.DEP.length > 2) {
zone = 'drom'
} else {
zone = 'metro'
}

const commune = {
code: row.COM,
nom: row.LIBELLE,
typeLiaison: parseTypeLiaison(row.TNCC)
typeLiaison: parseTypeLiaison(row.TNCC),
zone
}

if (row.TYPECOM === 'COM') {
Expand Down
44 changes: 39 additions & 5 deletions build/collectivites-outremer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
const {readCsvFile} = require('./util')

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

async function extractCommunesCOM(path) {
const rows = await readCsvFile(path)

return rows.map(row => {
const commune = {
code: row.code_commune,
nom: row.nom_commune,
collectiviteOutremer: {
code: row.code_collectivite,
nom: row.nom_collectivite
},
departement: row.code_collectivite,
region: row.code_collectivite,
zone: 'com',
type: 'commune-actuelle'
}

Expand All @@ -30,4 +40,28 @@ async function extractCommunesCOM(path) {
})
}

module.exports = {extractCommunesCOM}
async function generateDepartementsAndRegionsCOM(path) {
const rows = await readCsvFile(path)

const departements = Object.values(rows.reduce((acc, curr) => {
if (!(curr.code_collectivite in acc)) {
acc[curr.code_collectivite] = {
code: curr.code_collectivite,
region: curr.code_collectivite,
chefLieu: chefLieuCOM[curr.code_collectivite],
nom: curr.nom_collectivite,
typeLiaison: 0,
zone: 'com'
}
}
return acc
}, {}))

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

module.exports = {extractCommunesCOM, generateDepartementsAndRegionsCOM}
9 changes: 6 additions & 3 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {extractEPCI} = require('./epci')
const {extractPopulation, computeMLPPopulation} = require('./population')
const {getCodesPostaux, computeMLPCodesPostaux} = require('./codes-postaux')
const {MLP_CODES} = require('./mlp')
const {extractCommunesCOM} = require('./collectivites-outremer')
const {extractCommunesCOM, generateDepartementsAndRegionsCOM} = require('./collectivites-outremer')
const {extractDepartements, extractRegions, extractArrondissements, extractCommunes} = require('./cog')
const {writeData, getSourceFilePath} = require('./util')

Expand Down Expand Up @@ -70,8 +70,11 @@ async function main() {
communes: {...populationHorsMayotte.communes, ...populationMayotte.communes}
}
const arrondissements = await extractArrondissements(getSourceFilePath('arrondissements.csv'))
const departements = await extractDepartements(getSourceFilePath('departements.csv'))
const regions = await extractRegions(getSourceFilePath('regions.csv'))
const departementsMetroAndDrom = await extractDepartements(getSourceFilePath('departements.csv'))
const [departementsCom, regionsCom] = await generateDepartementsAndRegionsCOM(getSourceFilePath('collectivites-outremer.csv'))
const departements = [...departementsMetroAndDrom, ...departementsCom]
const regionsMetroAndDrom = await extractRegions(getSourceFilePath('regions.csv'))
const regions = [...regionsMetroAndDrom, ...regionsCom]

await buildRegions(regions)
await buildDepartements(departements)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etalab/decoupage-administratif",
"version": "2.0.0",
ThomasG77 marked this conversation as resolved.
Show resolved Hide resolved
"version": "2.1.0",
"description": "API JavaScript permettant d'interroger le découpage administratif français",
"main": ".",
"repository": "https://github.com/etalab/decoupage-administratif",
Expand Down