enable limit on department
This commit is contained in:
parent
9442153b32
commit
34aa2d9821
|
@ -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.
|
||||||
|
|
|
@ -5,10 +5,23 @@ import fs from 'node-fs';
|
||||||
|
|
||||||
|
|
||||||
let show_debug = 0;
|
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 sourceFileChargemapJson = './chargemap_data/hurepoix.json'
|
||||||
let sourceFileIRVEGeoJson = './etalab_data/consolidation-etalab-schema-irve-statique-v-2.2.0-20230727.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
|
* 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",
|
nbre_pdc: "chargin_point:count",
|
||||||
id_station_itinerance: "ref:EU:EVSE",
|
id_station_itinerance: "ref:EU:EVSE",
|
||||||
id_station_local: "ref",
|
id_station_local: "ref",
|
||||||
|
consolidated_code_postal: "zipcode",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +43,7 @@ function debugLog(message) {
|
||||||
console.log('debug: ', ...message)
|
console.log('debug: ', ...message)
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertDataForIRVE(sourceFilePath, mapping) {
|
function convertDataForIRVE(sourceFilePath, mapping, pointCounterMax) {
|
||||||
debugLog('convertDataFromChargemap from ', sourceFilePath);
|
debugLog('convertDataFromChargemap from ', sourceFilePath);
|
||||||
|
|
||||||
let convertedGeoJson = {
|
let convertedGeoJson = {
|
||||||
|
@ -54,12 +68,22 @@ function convertDataForIRVE(sourceFilePath, mapping) {
|
||||||
let listOfPoints = dataTransformed.features
|
let listOfPoints = dataTransformed.features
|
||||||
// for each point from the data source, convert with the mapping
|
// for each point from the data source, convert with the mapping
|
||||||
|
|
||||||
|
console.log('listOfPoints.length', listOfPoints.length)
|
||||||
listOfPoints.forEach(featurePoint => {
|
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', featurePoint)
|
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)
|
||||||
|
|
||||||
let mappedPoint = mapElementFromConf(featurePoint, mapping)
|
let mappedPoint = mapElementFromConf(featurePoint, mapping)
|
||||||
debugLog('map one point', featurePoint, mappedPoint)
|
debugLog('map one point', featurePoint, mappedPoint)
|
||||||
|
@ -67,10 +91,12 @@ function convertDataForIRVE(sourceFilePath, mapping) {
|
||||||
convertedGeoJson.features.push(mappedPoint)
|
convertedGeoJson.features.push(mappedPoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// }
|
||||||
pointcounter++;
|
pointcounter++;
|
||||||
|
|
||||||
})
|
})
|
||||||
// output new geojson
|
// output new geojson
|
||||||
|
console.log('convertedGeoJson.features.length', convertedGeoJson.features.length)
|
||||||
// write file on disk
|
// write file on disk
|
||||||
writeJsonFile('my_converted_data_set.json', JSON.stringify(convertedGeoJson, null, 2))
|
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 mappingKeys = Object.keys(mappingConfig)
|
||||||
let featurePointPropertiesKeys = Object.keys(featurePoint.properties)
|
let featurePointPropertiesKeys = Object.keys(featurePoint.properties)
|
||||||
|
|
||||||
console.log('keys', mappingKeys, featurePointPropertiesKeys)
|
debugLog('keys', mappingKeys, featurePointPropertiesKeys)
|
||||||
|
|
||||||
let newProperties = {}
|
let newProperties = {}
|
||||||
|
|
||||||
|
@ -103,12 +129,12 @@ function mapElementFromConf(featurePoint, mappingConfig) {
|
||||||
featurePointPropertiesKeys.forEach(pointKeyName => {
|
featurePointPropertiesKeys.forEach(pointKeyName => {
|
||||||
|
|
||||||
if (mappingKeys.indexOf(pointKeyName) !== -1) {
|
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]
|
newProperties[mappingConfig[pointKeyName]] = featurePoint.properties[pointKeyName]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('basePoint', basePoint)
|
debugLog('basePoint', basePoint)
|
||||||
return 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)
|
// convertDataFromChargemap(sourceFileChargemapJson, mappingConfigIRVE)
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue