enable limit on department

This commit is contained in:
Tykayn 2023-07-29 17:19:56 +02:00 committed by tykayn
parent 9442153b32
commit 34aa2d9821
3 changed files with 3515 additions and 18 deletions

View File

@ -0,0 +1,9 @@
# Conversion de jeux de données geojson en tags OSM
npm i
node convert_to_osm_tags.mjs
résultat dans le dossier output.
Réalisé pour l'intégration des bornes elec.

View File

@ -5,10 +5,23 @@ import fs from 'node-fs';
let show_debug = 0;
let limitConversionToFirstPoint = true;
let filterCoordinates = true;
let filterDepartment = 91;
let filterZipCode = new RegExp(`^${filterDepartment}`);
let pointCounterMax = 10;
// let limitConversionToFirstPoint = false;
// if (limitConversionToFirstPoint) {
// pointCounterMax = 1
// }
// limitConversionToFirstPoint = false;
// let sourceFileChargemapJson = './chargemap_data/hurepoix.json'
let sourceFileIRVEGeoJson = './etalab_data/consolidation-etalab-schema-irve-statique-v-2.2.0-20230727.json'
/**
* plan de conversion des clés du jeu de données vers les tags OSM
*/
@ -19,6 +32,7 @@ let mappingConfigIRVE = {
nbre_pdc: "chargin_point:count",
id_station_itinerance: "ref:EU:EVSE",
id_station_local: "ref",
consolidated_code_postal: "zipcode",
}
@ -29,7 +43,7 @@ function debugLog(message) {
console.log('debug: ', ...message)
}
function convertDataForIRVE(sourceFilePath, mapping) {
function convertDataForIRVE(sourceFilePath, mapping, pointCounterMax) {
debugLog('convertDataFromChargemap from ', sourceFilePath);
let convertedGeoJson = {
@ -54,23 +68,35 @@ function convertDataForIRVE(sourceFilePath, mapping) {
let listOfPoints = dataTransformed.features
// for each point from the data source, convert with the mapping
console.log('listOfPoints.length', listOfPoints.length)
listOfPoints.forEach(featurePoint => {
let regextestresult = filterZipCode.test(featurePoint.properties.consolidated_code_postal)
if (limitConversionToFirstPoint && (pointcounter < 2)) {
// filter points depending on zipcode
if (filterCoordinates && regextestresult) {
console.log('featurePoint.properties.consolidated_code_postal', featurePoint.properties.consolidated_code_postal)
// limit results number of points
// if (pointcounter < pointCounterMax) {
console.log('add point')
debugLog('featurePoint', featurePoint)
console.log('featurePoint', featurePoint)
let mappedPoint = mapElementFromConf(featurePoint, mapping)
debugLog('map one point', featurePoint, mappedPoint)
if (mappedPoint) {
convertedGeoJson.features.push(mappedPoint)
}
}
// }
pointcounter++;
})
// output new geojson
console.log('convertedGeoJson.features.length', convertedGeoJson.features.length)
// write file on disk
writeJsonFile('my_converted_data_set.json', JSON.stringify(convertedGeoJson, null, 2))
@ -89,7 +115,7 @@ function mapElementFromConf(featurePoint, mappingConfig) {
let mappingKeys = Object.keys(mappingConfig)
let featurePointPropertiesKeys = Object.keys(featurePoint.properties)
console.log('keys', mappingKeys, featurePointPropertiesKeys)
debugLog('keys', mappingKeys, featurePointPropertiesKeys)
let newProperties = {}
@ -103,12 +129,12 @@ function mapElementFromConf(featurePoint, mappingConfig) {
featurePointPropertiesKeys.forEach(pointKeyName => {
if (mappingKeys.indexOf(pointKeyName) !== -1) {
console.log('found element', pointKeyName, '=>', mappingConfig[pointKeyName], 'value : ', featurePoint.properties[pointKeyName])
debugLog('found element', pointKeyName, '=>', mappingConfig[pointKeyName], 'value : ', featurePoint.properties[pointKeyName])
newProperties[mappingConfig[pointKeyName]] = featurePoint.properties[pointKeyName]
}
})
console.log('basePoint', basePoint)
debugLog('basePoint', basePoint)
return basePoint
}
@ -130,6 +156,8 @@ function writeJsonFile(fileName, fileContent) {
);
}
convertDataForIRVE(sourceFileIRVEGeoJson, mappingConfigIRVE)
console.log('pointCounterMax', pointCounterMax)
convertDataForIRVE(sourceFileIRVEGeoJson, mappingConfigIRVE, pointCounterMax)
// convertDataFromChargemap(sourceFileChargemapJson, mappingConfigIRVE)

File diff suppressed because it is too large Load Diff