add filter on bounding coordinates

This commit is contained in:
Tykayn 2023-07-29 22:10:50 +02:00 committed by tykayn
parent 6ed29f8a93
commit 72c335d270
2 changed files with 5081 additions and 13 deletions

View File

@ -6,24 +6,38 @@ import fs from 'node-fs';
let show_debug = 0; let show_debug = 0;
// wip filter
let filterOnBoundingBox = true
let boundingBoxCoordinates ={
xMin: 1.91,
yMin: 48.7,
xMax: 2.38,
yMax: 48.4,
}
let filterCoordinates = true; let filterCoordinates = true;
let filterDepartment = 974; let enableFilterOnDepartment = false;
let filterDepartment = 91;
let filterZipCode = new RegExp(`^${filterDepartment}`); let filterZipCode = new RegExp(`^${filterDepartment}`);
let filterZipCodeAdresse = new RegExp(` ${filterDepartment}`); let filterZipCodeAdresse = new RegExp(` ${filterDepartment}`);
let filteredName ='' let filteredName =''
if(filterCoordinates){ if(enableFilterOnDepartment){
filteredName = '_filtered_zipcode_'+filterDepartment filteredName = '_filtered_zipcode_'+filterDepartment
} }
if(filterOnBoundingBox){
filteredName = '_filtered_bbox_'+boundingBoxCoordinates.xMin+'-'+boundingBoxCoordinates.xMax+'_'+boundingBoxCoordinates.yMin+'-'+boundingBoxCoordinates.yMax
}
let pointCounterMax = 1000000; let pointCounterMax = 1000000;
// let limitConversionToFirstPoint = false; let limitConversionToFirstPoint = false;
// if (limitConversionToFirstPoint) { // limitConversionToFirstPoint = true;
// pointCounterMax = 1 if (limitConversionToFirstPoint) {
// } pointCounterMax = 1
}
// limitConversionToFirstPoint = false;
// let sourceFileChargemapJson = './chargemap_data/hurepoix.json' // let sourceFileChargemapJson = './chargemap_data/hurepoix.json'
let sourceFileIRVEGeoJson = './etalab_data/latest.json' let sourceFileIRVEGeoJson = './etalab_data/latest.json'
@ -105,11 +119,33 @@ function convertDataForIRVE(sourceFilePath, mapping, pointCounterMax) {
console.log('listOfPoints.length', listOfPoints.length) console.log('listOfPoints.length', listOfPoints.length)
listOfPoints.forEach(featurePoint => { listOfPoints.forEach(featurePoint => {
let regextestresult = ( let regextestresult = true;
filterZipCode.test(featurePoint.properties.consolidated_code_postal)
||  if(enableFilterOnDepartment){
filterZipCodeAdresse.test(featurePoint.properties.adresse_station) console.log('filtre sur les départements activé')
) regextestresult = (
filterZipCode.test(featurePoint.properties.consolidated_code_postal)
||
filterZipCodeAdresse.test(featurePoint.properties.adresse_station)
)
}else if(filterOnBoundingBox){
console.log('filtre sur les coordonnées activé')
let x = coordonneesXY[0]
let xMin = boundingBoxCoordinates.xMin
let xMax = boundingBoxCoordinates.xMax
let yMin = boundingBoyCoordinates.yMin
let yMax = boundingBoyCoordinates.yMay
let y = coordonneesXY[1]
regextestresult = (
filterZipCode.test(x >= xMin && x <= xMax)
&&
filterZipCode.test(y >= yMin && y <= yMax)
)
}
// filter points depending on zipcode // filter points depending on zipcode