Navigation Menu

Skip to content

Commit

Permalink
Plus de souplesse dans l'appariement PCI
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesboeufs committed Nov 15, 2019
1 parent 6d2a514 commit fc059ee
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
7 changes: 6 additions & 1 deletion improve-csv.js
Expand Up @@ -136,7 +136,12 @@ async function main() {
const parcelles = await getParcellesCommune(codeCommune)

communeRows.forEach(row => {
if (parcelles && row.id_parcelle in parcelles) {
if (row.ancien_id_parcelle in parcelles) {
row.id_parcelle = row.ancien_id_parcelle
row.ancien_id_parcelle = undefined
}

if (row.id_parcelle in parcelles) {
const parcelle = parcelles[row.id_parcelle]
const [lon, lat] = truncate(centroid(parcelle), {precision: 6}).geometry.coordinates
row.longitude = lon
Expand Down
25 changes: 16 additions & 9 deletions lib/parcelles.js
Expand Up @@ -3,22 +3,29 @@ const {join} = require('path')
const gunzip = promisify(require('zlib').gunzip)
const {readFile, pathExists} = require('fs-extra')
const {keyBy} = require('lodash')
const {getCodeDepartement} = require('./recog')
const {getCodeDepartement, getAllCodesCommunes} = require('./recog')

const communesPath = process.env.CADASTRE_COMMUNES_PATH

async function getParcellesCommune(codeCommune) {
const filePath = join(communesPath, getCodeDepartement(codeCommune), codeCommune, `cadastre-${codeCommune}-parcelles.json.gz`)
const codesCommunes = getAllCodesCommunes(codeCommune)
const parcelles = []

if (!(await pathExists(filePath))) {
return
}
await Promise.all(codesCommunes.map(async code => {
const filePath = join(communesPath, getCodeDepartement(code), code, `cadastre-${code}-parcelles.json.gz`)

const gzippedFileContent = await readFile(filePath)
const fileContent = await gunzip(gzippedFileContent)
const featureCollection = JSON.parse(fileContent)
if (!(await pathExists(filePath))) {
return
}

return keyBy(featureCollection.features, 'properties.id')
const gzippedFileContent = await readFile(filePath)
const fileContent = await gunzip(gzippedFileContent)
const featureCollection = JSON.parse(fileContent)

parcelles.push(...featureCollection.features)
}))

return keyBy(parcelles, 'properties.id')
}

module.exports = {getParcellesCommune}
7 changes: 6 additions & 1 deletion lib/recog.js
Expand Up @@ -127,4 +127,9 @@ function getCommuneActuelle(communeEntry, dateValeur) {
}
}

module.exports = {getCodeDepartement, getCommune, isValidAt, getCommuneActuelle, getCommuneFromCadastre}
function getAllCodesCommunes(codeCommune) {
const commune = getCommune(codeCommune)
return getCodesMembres(commune)
}

module.exports = {getAllCodesCommunes, getCodeDepartement, getCommune, isValidAt, getCommuneActuelle, getCommuneFromCadastre}

0 comments on commit fc059ee

Please sign in to comment.