add config ask angela
This commit is contained in:
parent
e1688352d1
commit
a41fd19c35
@ -17,17 +17,18 @@ import mappingFINESS from "./mappings/converters/configFINESS";
|
|||||||
import MappingArbresIssy from "./mappings/converters/configArbresIssy";
|
import MappingArbresIssy from "./mappings/converters/configArbresIssy";
|
||||||
import MappingArbres92 from "./mappings/converters/configArbresHautsDeSeine";
|
import MappingArbres92 from "./mappings/converters/configArbresHautsDeSeine";
|
||||||
import MappingMuseums from "./mappings/converters/configMuseums";
|
import MappingMuseums from "./mappings/converters/configMuseums";
|
||||||
|
import MappingRouenPAV from "./mappings/converters/configRouen_PAV";
|
||||||
|
import MappingAskAngela from "mappings/converters/configAskAngela";
|
||||||
|
|
||||||
const limitWarningPercentageChangeInPoints = 5; // show a warning when more than N percent of the number of points changed
|
const limitWarningPercentageChangeInPoints = 5; // show a warning when more than N percent of the number of points changed
|
||||||
const allowed_configs = [
|
const allowed_configs = [
|
||||||
'mappingIssy2Roues', 'mappingConfigIRVE', 'mappingConfigIRVEFromOsmose',
|
'mappingIssy2Roues', 'mappingConfigIRVE', 'mappingConfigIRVEFromOsmose',
|
||||||
'mappingConfigIRVE_simple', 'mappingTest', 'ConfigIRVE',
|
'mappingConfigIRVE_simple', 'mappingTest', 'ConfigIRVE',
|
||||||
'mappingRouenParkingVelos', 'mappingFINESS', 'MappingArbresIssy',
|
'mappingRouenParkingVelos', 'mappingFINESS', 'MappingArbresIssy',
|
||||||
'MappingArbres92', 'MappingMuseums','MappingRouenPAV'
|
'MappingArbres92', 'MappingMuseums', 'MappingRouenPAV', 'MappingAskAngela'
|
||||||
];
|
];
|
||||||
|
|
||||||
import minimist = require('minimist')
|
import minimist = require('minimist');
|
||||||
import MappingRouenPAV from "./mappings/converters/configRouen_PAV";
|
|
||||||
|
|
||||||
const debugLog = utils.debugLog;
|
const debugLog = utils.debugLog;
|
||||||
|
|
||||||
@ -39,13 +40,13 @@ let sourceFilePathGeoJson = './data_other/' + output_supplement + '.json'
|
|||||||
let filterOnBoundingBox = true
|
let filterOnBoundingBox = true
|
||||||
filterOnBoundingBox = false
|
filterOnBoundingBox = false
|
||||||
let boundingBoxCoordinates: BoundingBoxCoordinatesType = {
|
let boundingBoxCoordinates: BoundingBoxCoordinatesType = {
|
||||||
xMin: 1.91,
|
xMin: 1.91,
|
||||||
xMax: 2.38,
|
xMax: 2.38,
|
||||||
yMin: 48.7,
|
yMin: 48.7,
|
||||||
yMax: 48.4,
|
yMax: 48.4,
|
||||||
}
|
}
|
||||||
let default_engine_conf_choice: string = 'ConfigIRVE';
|
let default_engine_conf_choice: string = 'ConfigIRVE'
|
||||||
let engine_conf_choice: string = 'ConfigIRVE';
|
let engine_conf_choice: string = 'ConfigIRVE'
|
||||||
let filterCoordinates = true
|
let filterCoordinates = true
|
||||||
filterCoordinates = false
|
filterCoordinates = false
|
||||||
|
|
||||||
@ -54,39 +55,39 @@ enable_filter_on_department = false
|
|||||||
|
|
||||||
let filterDepartment = 91
|
let filterDepartment = 91
|
||||||
if (mini_arguments['department']) {
|
if (mini_arguments['department']) {
|
||||||
filterDepartment = mini_arguments['department']
|
filterDepartment = mini_arguments['department']
|
||||||
enable_filter_on_department = true
|
enable_filter_on_department = true
|
||||||
}
|
}
|
||||||
let osmoseFormat = false;
|
let osmoseFormat = false;
|
||||||
if (mini_arguments['osmose']) {
|
if (mini_arguments['osmose']) {
|
||||||
osmoseFormat = mini_arguments['osmose']
|
osmoseFormat = mini_arguments['osmose']
|
||||||
}
|
}
|
||||||
if (mini_arguments['source']) {
|
if (mini_arguments['source']) {
|
||||||
sourceFilePathGeoJson = mini_arguments['source']
|
sourceFilePathGeoJson = mini_arguments['source']
|
||||||
|
|
||||||
}
|
}
|
||||||
if (mini_arguments['engine']) {
|
if (mini_arguments['engine']) {
|
||||||
use_mapping_engine = mini_arguments['engine']
|
use_mapping_engine = mini_arguments['engine']
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mini_arguments['engine-config']) {
|
if (mini_arguments['engine-config']) {
|
||||||
engine_conf_choice = mini_arguments['engine-config']
|
engine_conf_choice = mini_arguments['engine-config']
|
||||||
output_supplement += "_" + engine_conf_choice
|
output_supplement += "_" + engine_conf_choice
|
||||||
}
|
}
|
||||||
let Mapping_engine: any;
|
let Mapping_engine: any;
|
||||||
let outname = 'converted_'
|
let outname = 'converted_'
|
||||||
|
|
||||||
if (mini_arguments['outname']) {
|
if (mini_arguments['outname']) {
|
||||||
outname = mini_arguments['outname'];
|
outname = mini_arguments['outname'];
|
||||||
}
|
}
|
||||||
if (mini_arguments['testingConfig']) {
|
if (mini_arguments['testingConfig']) {
|
||||||
console.log('testing')
|
console.log('testing')
|
||||||
Mapping_engine = new mapping_engine(mappingTest)
|
Mapping_engine = new mapping_engine(mappingTest)
|
||||||
} else if (osmoseFormat) {
|
} else if (osmoseFormat) {
|
||||||
console.log(' *********** we use osmose converter *********')
|
console.log(' *********** we use osmose converter *********')
|
||||||
Mapping_engine = new mapping_engine(mappingConfigIRVEFromOsmose)
|
Mapping_engine = new mapping_engine(mappingConfigIRVEFromOsmose)
|
||||||
} else {
|
} else {
|
||||||
Mapping_engine = new mapping_engine(mappingConfigIRVE)
|
Mapping_engine = new mapping_engine(mappingConfigIRVE)
|
||||||
}
|
}
|
||||||
|
|
||||||
let filterZipCode = new RegExp(`^${filterDepartment}`)
|
let filterZipCode = new RegExp(`^${filterDepartment}`)
|
||||||
@ -94,9 +95,9 @@ let filterZipCodeAdresse = new RegExp(` ${filterDepartment}`)
|
|||||||
let filteredName = ''
|
let filteredName = ''
|
||||||
|
|
||||||
if (enable_filter_on_department) {
|
if (enable_filter_on_department) {
|
||||||
filteredName = '_filtered_zipcode_' + filterDepartment
|
filteredName = '_filtered_zipcode_' + filterDepartment
|
||||||
} else if (filterOnBoundingBox) {
|
} else if (filterOnBoundingBox) {
|
||||||
filteredName = '_filtered_bbox_' + boundingBoxCoordinates.xMin + '-' + boundingBoxCoordinates.xMax + '_' + boundingBoxCoordinates.yMin + '-' + boundingBoxCoordinates.yMax
|
filteredName = '_filtered_bbox_' + boundingBoxCoordinates.xMin + '-' + boundingBoxCoordinates.xMax + '_' + boundingBoxCoordinates.yMin + '-' + boundingBoxCoordinates.yMax
|
||||||
}
|
}
|
||||||
let pointCounterMax: number = 1000000
|
let pointCounterMax: number = 1000000
|
||||||
|
|
||||||
@ -104,15 +105,15 @@ let limitConversionToFirstPoint: boolean = false
|
|||||||
// limitConversionToFirstPoint = true
|
// limitConversionToFirstPoint = true
|
||||||
|
|
||||||
if (limitConversionToFirstPoint) {
|
if (limitConversionToFirstPoint) {
|
||||||
pointCounterMax = 1
|
pointCounterMax = 1
|
||||||
}
|
}
|
||||||
let defaultPropertiesOfPoint: any = {
|
let defaultPropertiesOfPoint: any = {
|
||||||
'amenity': 'charging_station'
|
'amenity': 'charging_station'
|
||||||
}
|
}
|
||||||
|
|
||||||
let converted_geo_json: any = {
|
let converted_geo_json: any = {
|
||||||
type: 'FeatureCollection',
|
type: 'FeatureCollection',
|
||||||
features: []
|
features: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -124,23 +125,23 @@ let output_folder = 'output';
|
|||||||
* @param fileContent
|
* @param fileContent
|
||||||
*/
|
*/
|
||||||
function writeFile(fileName: string, fileContent: any) {
|
function writeFile(fileName: string, fileContent: any) {
|
||||||
let write_path = `./${output_folder}/${fileName}`
|
let write_path = `./${output_folder}/${fileName}`
|
||||||
debugLog("write file \n", outname + fileName, write_path)
|
debugLog("write file \n", outname + fileName, write_path)
|
||||||
|
|
||||||
console.log("-------- write file \n", fileName, "\n", write_path)
|
console.log("-------- write file \n", fileName, "\n", write_path)
|
||||||
|
|
||||||
return fs.writeFile(
|
return fs.writeFile(
|
||||||
write_path,
|
write_path,
|
||||||
fileContent,
|
fileContent,
|
||||||
'utf8',
|
'utf8',
|
||||||
(err) => {
|
(err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
debugLog(`Error writing file: ${err}`)
|
debugLog(`Error writing file: ${err}`)
|
||||||
} else {
|
} else {
|
||||||
debugLog(`File ${fileName} is written successfully!`)
|
debugLog(`File ${fileName} is written successfully!`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -151,266 +152,268 @@ function writeFile(fileName: string, fileContent: any) {
|
|||||||
* @param boundingBoxCoordinates
|
* @param boundingBoxCoordinates
|
||||||
*/
|
*/
|
||||||
function convertDataFromSource(sourceFilePath: string, mapping: MappingConfigType, pointCounterMax: number, boundingBoxCoordinates: any) {
|
function convertDataFromSource(sourceFilePath: string, mapping: MappingConfigType, pointCounterMax: number, boundingBoxCoordinates: any) {
|
||||||
debugLog('convert data: source file from :', sourceFilePath)
|
debugLog('convert data: source file from :', sourceFilePath)
|
||||||
|
|
||||||
fs.readFile(sourceFilePath, 'utf8', function (err, data) {
|
fs.readFile(sourceFilePath, 'utf8', function (err, data) {
|
||||||
let point_counter = 0
|
let point_counter = 0
|
||||||
let feature_points_after_filter: any = []
|
let feature_points_after_filter: any = []
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return debugLog(err)
|
return debugLog(err)
|
||||||
|
}
|
||||||
|
let data_transformed: FeatureCollection = JSON.parse(data)
|
||||||
|
|
||||||
|
if (data_transformed.features) {
|
||||||
|
|
||||||
|
console.log('------ data found in source, features:', data_transformed.features.length)
|
||||||
|
|
||||||
|
// find interesting list of points to use
|
||||||
|
let list_of_points: any = data_transformed.features
|
||||||
|
debugLog('listOfPoints.length', list_of_points.length)
|
||||||
|
|
||||||
|
if (limitConversionToFirstPoint) {
|
||||||
|
debugLog('limitConversionToFirstPoint enabled')
|
||||||
|
if (mapping?.filters?.offset) {
|
||||||
|
mapping.filters.offset = 1
|
||||||
}
|
}
|
||||||
let data_transformed: FeatureCollection = JSON.parse(data)
|
}
|
||||||
|
if (mapping?.filters?.offset) {
|
||||||
|
debugLog('filter offset enabled', mapping.filters.offset)
|
||||||
|
list_of_points = list_of_points.splice(0, mapping.filters.offset)
|
||||||
|
}
|
||||||
|
|
||||||
if (data_transformed.features) {
|
console.log('features count before:', list_of_points.length)
|
||||||
|
|
||||||
console.log('------ data found in source, features:', data_transformed.features.length)
|
|
||||||
|
|
||||||
// find interesting list of points to use
|
|
||||||
let list_of_points: any = data_transformed.features
|
|
||||||
debugLog('listOfPoints.length', list_of_points.length)
|
|
||||||
|
|
||||||
if (limitConversionToFirstPoint) {
|
|
||||||
debugLog('limitConversionToFirstPoint enabled')
|
|
||||||
if (mapping?.filters?.offset) {
|
|
||||||
mapping.filters.offset = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mapping?.filters?.offset) {
|
|
||||||
debugLog('filter offset enabled', mapping.filters.offset)
|
|
||||||
list_of_points = list_of_points.splice(0, mapping.filters.offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('features count before:', list_of_points.length)
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* filtering
|
* filtering
|
||||||
* run filters before mapping OSM tags
|
* run filters before mapping OSM tags
|
||||||
*/
|
*/
|
||||||
if (mapping.filters && mapping.filters.exclude_point_if_tag_not_empty) {
|
if (mapping.filters && mapping.filters.exclude_point_if_tag_not_empty) {
|
||||||
list_of_points = Mapping_engine.filterListOfPointsByExcludingIfKeyFilled(list_of_points, mapping.filters.exclude_point_if_tag_not_empty)
|
list_of_points = Mapping_engine.filterListOfPointsByExcludingIfKeyFilled(list_of_points, mapping.filters.exclude_point_if_tag_not_empty)
|
||||||
}
|
}
|
||||||
|
|
||||||
// for each point from the data source, filter if we take it or not
|
// for each point from the data source, filter if we take it or not
|
||||||
list_of_points.forEach((feature_point: any) => {
|
list_of_points.forEach((feature_point: any) => {
|
||||||
|
|
||||||
let regex_filter_test_result = true
|
let regex_filter_test_result = true
|
||||||
let remove_original_key = false;
|
let remove_original_key = false;
|
||||||
feature_point.properties.tags?.forEach((tagKey: string, tagValue: string) => {
|
feature_point.properties.tags?.forEach((tagKey: string, tagValue: string) => {
|
||||||
if (mapping.filters && mapping.filters.exclude_point_if_tag_not_empty?.indexOf(tagKey) !== -1
|
if (mapping.filters && mapping.filters.exclude_point_if_tag_not_empty?.indexOf(tagKey) !== -1
|
||||||
&& tagValue.length
|
&& tagValue.length
|
||||||
&& tagValue !== 'null') {
|
&& tagValue !== 'null') {
|
||||||
remove_original_key = true;
|
remove_original_key = true;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (remove_original_key) {
|
if (remove_original_key) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (enable_filter_on_department) {
|
|
||||||
debugLog('filtre sur les départements activé')
|
|
||||||
regex_filter_test_result = (
|
|
||||||
filterZipCode.test(feature_point.properties.consolidated_code_postal)
|
|
||||||
||
|
|
||||||
filterZipCodeAdresse.test(feature_point.properties.adresse_station)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
debugLog('pas de filtre sur les départements')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filterOnBoundingBox) {
|
|
||||||
debugLog('filtre sur les coordonnées bounding box activé')
|
|
||||||
|
|
||||||
let x = feature_point.properties.coordonneesXY[0]
|
|
||||||
let xMin = boundingBoxCoordinates.xMin
|
|
||||||
let xMax = boundingBoxCoordinates.xMax
|
|
||||||
let yMin = boundingBoxCoordinates.yMin
|
|
||||||
let yMax = boundingBoxCoordinates.yMax
|
|
||||||
|
|
||||||
let y = feature_point.properties.coordonneesXY[1]
|
|
||||||
regex_filter_test_result = (
|
|
||||||
(x >= xMin && x <= xMax)
|
|
||||||
&&
|
|
||||||
(y >= yMin && y <= yMax)
|
|
||||||
)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
debugLog('pas de filtre sur les coordonnées bounding box')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// TODO add filter offset max
|
|
||||||
// filter points depending on zipcode
|
|
||||||
if (regex_filter_test_result) {
|
|
||||||
feature_points_after_filter.push(feature_point)
|
|
||||||
debugLog(' +1 point', point_counter)
|
|
||||||
point_counter++
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
|
||||||
* conversion
|
|
||||||
*/
|
|
||||||
debugLog(' after filtering, feature_points_after_filter number of points: ', feature_points_after_filter.length)
|
|
||||||
feature_points_after_filter.forEach((feature_point: any) => {
|
|
||||||
debugLog('convert : work on 1 point')
|
|
||||||
let mapped_point: any = {}
|
|
||||||
|
|
||||||
if (use_mapping_engine) {
|
|
||||||
mapped_point = Mapping_engine.mapElementFromConf(feature_point)
|
|
||||||
debugLog('mapped_point', mapped_point)
|
|
||||||
} else {
|
|
||||||
debugLog('convert :using simple converter on feature point', feature_point)
|
|
||||||
mapped_point = mapElementFromConfSimple(feature_point, mapping)
|
|
||||||
}
|
|
||||||
if (mapped_point) {
|
|
||||||
converted_geo_json.features.push(mapped_point)
|
|
||||||
debugLog('convert : added one point to converted_geo_json')
|
|
||||||
} else {
|
|
||||||
debugLog('convert : !!! there is no map one point')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// output new geojson
|
|
||||||
|
|
||||||
debugLog('convert : convertedGeoJson.features.length', converted_geo_json.features.length)
|
|
||||||
|
|
||||||
// write file on disk
|
|
||||||
if (converted_geo_json.features.length) {
|
|
||||||
|
|
||||||
|
|
||||||
if (output_supplement) {
|
|
||||||
output_supplement = '_' + output_supplement;
|
|
||||||
}
|
|
||||||
let fileNameToWrite = '_' + filteredName + output_supplement + '.geojson'
|
|
||||||
console.log('converted features:', converted_geo_json.features.length)
|
|
||||||
console.log('différences nombre de features: ', data_transformed.features.length - converted_geo_json.features.length)
|
|
||||||
|
|
||||||
const percentChange = (data_transformed.features.length - converted_geo_json.features.length) / converted_geo_json.features.length * 100;
|
|
||||||
console.log('Changement de features', percentChange, '%')
|
|
||||||
|
|
||||||
if (percentChange > limitWarningPercentageChangeInPoints) {
|
|
||||||
console.log(' /!\\ pas mal de points en moins, plus de ' + percentChange + '%')
|
|
||||||
}
|
|
||||||
debugLog('convert : write file ', fileNameToWrite)
|
|
||||||
|
|
||||||
// console.log('mapping_engine.stats', Mapping_engine.stats)
|
|
||||||
console.log('mapping config name:', Mapping_engine.getConfig().config_name)
|
|
||||||
writeFile(fileNameToWrite, JSON.stringify(converted_geo_json, null, 2))
|
|
||||||
|
|
||||||
} else {
|
|
||||||
console.log('convert : no writing of file, because there is no converted feature')
|
|
||||||
}
|
|
||||||
|
|
||||||
return converted_geo_json
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
|
if (enable_filter_on_department) {
|
||||||
|
debugLog('filtre sur les départements activé')
|
||||||
|
regex_filter_test_result = (
|
||||||
|
filterZipCode.test(feature_point.properties.consolidated_code_postal)
|
||||||
|
||
|
||||||
|
filterZipCodeAdresse.test(feature_point.properties.adresse_station)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
debugLog('pas de filtre sur les départements')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filterOnBoundingBox) {
|
||||||
|
debugLog('filtre sur les coordonnées bounding box activé')
|
||||||
|
|
||||||
|
let x = feature_point.properties.coordonneesXY[0]
|
||||||
|
let xMin = boundingBoxCoordinates.xMin
|
||||||
|
let xMax = boundingBoxCoordinates.xMax
|
||||||
|
let yMin = boundingBoxCoordinates.yMin
|
||||||
|
let yMax = boundingBoxCoordinates.yMax
|
||||||
|
|
||||||
|
let y = feature_point.properties.coordonneesXY[1]
|
||||||
|
regex_filter_test_result = (
|
||||||
|
(x >= xMin && x <= xMax)
|
||||||
|
&&
|
||||||
|
(y >= yMin && y <= yMax)
|
||||||
|
)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
debugLog('pas de filtre sur les coordonnées bounding box')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO add filter offset max
|
||||||
|
// filter points depending on zipcode
|
||||||
|
if (regex_filter_test_result) {
|
||||||
|
feature_points_after_filter.push(feature_point)
|
||||||
|
debugLog(' +1 point', point_counter)
|
||||||
|
point_counter++
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* conversion
|
||||||
|
*/
|
||||||
|
debugLog(' after filtering, feature_points_after_filter number of points: ', feature_points_after_filter.length)
|
||||||
|
feature_points_after_filter.forEach((feature_point: any) => {
|
||||||
|
debugLog('convert : work on 1 point')
|
||||||
|
let mapped_point: any = {}
|
||||||
|
|
||||||
|
if (use_mapping_engine) {
|
||||||
|
mapped_point = Mapping_engine.mapElementFromConf(feature_point)
|
||||||
|
debugLog('mapped_point', mapped_point)
|
||||||
|
} else {
|
||||||
|
debugLog('convert :using simple converter on feature point', feature_point)
|
||||||
|
mapped_point = mapElementFromConfSimple(feature_point, mapping)
|
||||||
|
}
|
||||||
|
if (mapped_point) {
|
||||||
|
converted_geo_json.features.push(mapped_point)
|
||||||
|
debugLog('convert : added one point to converted_geo_json')
|
||||||
|
} else {
|
||||||
|
debugLog('convert : !!! there is no map one point')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// output new geojson
|
||||||
|
|
||||||
|
debugLog('convert : convertedGeoJson.features.length', converted_geo_json.features.length)
|
||||||
|
|
||||||
|
// write file on disk
|
||||||
|
if (converted_geo_json.features.length) {
|
||||||
|
|
||||||
|
|
||||||
|
if (output_supplement) {
|
||||||
|
output_supplement = '_' + output_supplement;
|
||||||
|
}
|
||||||
|
let fileNameToWrite = '_' + filteredName + output_supplement + '.geojson'
|
||||||
|
console.log('converted features:', converted_geo_json.features.length)
|
||||||
|
console.log('différences nombre de features: ', data_transformed.features.length - converted_geo_json.features.length)
|
||||||
|
|
||||||
|
const percentChange = (data_transformed.features.length - converted_geo_json.features.length) / converted_geo_json.features.length * 100;
|
||||||
|
console.log('Changement de features', percentChange, '%')
|
||||||
|
|
||||||
|
if (percentChange > limitWarningPercentageChangeInPoints) {
|
||||||
|
console.log(' /!\\ pas mal de points en moins, plus de ' + percentChange + '%')
|
||||||
|
}
|
||||||
|
debugLog('convert : write file ', fileNameToWrite)
|
||||||
|
|
||||||
|
// console.log('mapping_engine.stats', Mapping_engine.stats)
|
||||||
|
console.log('mapping config name:', Mapping_engine.getConfig().config_name)
|
||||||
|
writeFile(fileNameToWrite, JSON.stringify(converted_geo_json, null, 2))
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log('convert : no writing of file, because there is no converted feature')
|
||||||
|
}
|
||||||
|
|
||||||
|
return converted_geo_json
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* retuns the converted element from mapping config if present, null otherwise
|
* retuns the converted element from mapping config if present, null otherwise
|
||||||
*/
|
*/
|
||||||
function mapElementFromConfSimple(featurePoint: any, mappingConfig: any) {
|
function mapElementFromConfSimple(featurePoint: any, mappingConfig: any) {
|
||||||
let mappingKeys = Object.keys(mappingConfig)
|
let mappingKeys = Object.keys(mappingConfig)
|
||||||
let featurePointPropertiesKeys = Object.keys(featurePoint.properties)
|
let featurePointPropertiesKeys = Object.keys(featurePoint.properties)
|
||||||
|
|
||||||
debugLog('keys', mappingKeys, featurePointPropertiesKeys)
|
debugLog('keys', mappingKeys, featurePointPropertiesKeys)
|
||||||
|
|
||||||
let newProperties: any = defaultPropertiesOfPoint
|
let newProperties: any = defaultPropertiesOfPoint
|
||||||
|
|
||||||
// reinit properties of current point
|
// reinit properties of current point
|
||||||
let basePoint = Object.create(featurePoint)
|
let basePoint = Object.create(featurePoint)
|
||||||
basePoint.type = featurePoint.type
|
basePoint.type = featurePoint.type
|
||||||
basePoint.geometry = featurePoint.geometry
|
basePoint.geometry = featurePoint.geometry
|
||||||
basePoint.properties = newProperties
|
basePoint.properties = newProperties
|
||||||
|
|
||||||
// apply new properties if found in mapping config
|
// apply new properties if found in mapping config
|
||||||
featurePointPropertiesKeys.forEach((pointKeyName: string) => {
|
featurePointPropertiesKeys.forEach((pointKeyName: string) => {
|
||||||
|
|
||||||
if (mappingKeys.indexOf(pointKeyName) !== -1) {
|
if (mappingKeys.indexOf(pointKeyName) !== -1) {
|
||||||
// debugLog('found element', pointKeyName, '=>', mappingConfig[pointKeyName], 'value : ', featurePoint.properties[pointKeyName])
|
// debugLog('found element', pointKeyName, '=>', mappingConfig[pointKeyName], 'value : ', featurePoint.properties[pointKeyName])
|
||||||
let convertedValue: any = ''
|
let convertedValue: any = ''
|
||||||
if (utils.isBooleanKey(pointKeyName)) {
|
if (utils.isBooleanKey(pointKeyName)) {
|
||||||
|
|
||||||
let copyOfValue: any = '' + featurePoint.properties[pointKeyName]
|
let copyOfValue: any = '' + featurePoint.properties[pointKeyName]
|
||||||
if (typeof copyOfValue === typeof Object && copyOfValue.key_converted) {
|
if (typeof copyOfValue === typeof Object && copyOfValue.key_converted) {
|
||||||
copyOfValue = copyOfValue.key_converted
|
copyOfValue = copyOfValue.key_converted
|
||||||
}
|
|
||||||
convertedValue = copyOfValue.toLowerCase() == 'true' ? 'yes' : 'no'
|
|
||||||
} else {
|
|
||||||
convertedValue = featurePoint.properties[pointKeyName]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (convertedValue) {
|
|
||||||
let convertedKey: any = mappingConfig[pointKeyName]
|
|
||||||
newProperties[convertedKey] = convertedValue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
convertedValue = copyOfValue.toLowerCase() == 'true' ? 'yes' : 'no'
|
||||||
|
} else {
|
||||||
|
convertedValue = featurePoint.properties[pointKeyName]
|
||||||
|
}
|
||||||
|
|
||||||
debugLog('basePoint', basePoint)
|
if (convertedValue) {
|
||||||
return basePoint
|
let convertedKey: any = mappingConfig[pointKeyName]
|
||||||
|
newProperties[convertedKey] = convertedValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
debugLog('basePoint', basePoint)
|
||||||
|
return basePoint
|
||||||
}
|
}
|
||||||
|
|
||||||
function setMappingConfigFromName(engine_conf_choice: string) {
|
function setMappingConfigFromName(engine_conf_choice: string) {
|
||||||
console.log('------- use_mapping_engine', use_mapping_engine)
|
console.log('------- use_mapping_engine', use_mapping_engine)
|
||||||
console.log('------- engine_conf_choice', engine_conf_choice)
|
console.log('------- engine_conf_choice', engine_conf_choice)
|
||||||
|
|
||||||
if (use_mapping_engine) {
|
if (use_mapping_engine) {
|
||||||
debugLog(' - using mapping engine')
|
debugLog(' - using mapping engine')
|
||||||
debugLog(' - pointCounterMax', pointCounterMax)
|
debugLog(' - pointCounterMax', pointCounterMax)
|
||||||
|
|
||||||
if (osmoseFormat) {
|
if (osmoseFormat) {
|
||||||
Mapping_engine.setConfig(mappingConfigIRVEFromOsmose)
|
Mapping_engine.setConfig(mappingConfigIRVEFromOsmose)
|
||||||
|
|
||||||
} else {
|
|
||||||
// choisir la config IRVE par défaut si aucune option de config de mapping n'est choisie en CLI
|
|
||||||
|
|
||||||
|
|
||||||
if (engine_conf_choice !== default_engine_conf_choice && allowed_configs.indexOf("mappingIssy2Roues") !== -1) {
|
|
||||||
// ['mappingIssy2Roues', 'mappingConfigIRVE', 'mappingConfigIRVEFromOsmose', 'mappingConfigIRVE_simple', 'mappingTest', 'ConfigIRVE']
|
|
||||||
if (engine_conf_choice == 'mappingIssy2Roues') {
|
|
||||||
console.log('mappingIssy2Roues', mappingIssy2Roues)
|
|
||||||
Mapping_engine.setConfig(mappingIssy2Roues)
|
|
||||||
} else if (engine_conf_choice == 'mappingConfigIRVE') {
|
|
||||||
Mapping_engine.setConfig(mappingConfigIRVE)
|
|
||||||
} else if (engine_conf_choice == 'mappingConfigIRVEFromOsmose') {
|
|
||||||
Mapping_engine.setConfig(mappingConfigIRVEFromOsmose)
|
|
||||||
} else if (engine_conf_choice == 'mappingConfigIRVE_simple') {
|
|
||||||
Mapping_engine.setConfig(mappingConfigIRVE_simple)
|
|
||||||
} else if (engine_conf_choice == 'mappingTest') {
|
|
||||||
Mapping_engine.setConfig(mappingTest)
|
|
||||||
} else if (engine_conf_choice == 'ConfigIRVE') {
|
|
||||||
Mapping_engine.setConfig(ConfigIRVE)
|
|
||||||
} else if (engine_conf_choice == 'mappingRouenParkingVelos') {
|
|
||||||
Mapping_engine.setConfig(mappingRouenParkingVelos)
|
|
||||||
} else if (engine_conf_choice == 'MappingArbresIssy') {
|
|
||||||
Mapping_engine.setConfig(MappingArbresIssy)
|
|
||||||
} else if (engine_conf_choice == 'mappingFINESS') {
|
|
||||||
Mapping_engine.setConfig(mappingFINESS)
|
|
||||||
} else if (engine_conf_choice == 'MappingArbres92') {
|
|
||||||
Mapping_engine.setConfig(MappingArbres92)
|
|
||||||
} else if (engine_conf_choice == 'MappingMuseums') {
|
|
||||||
Mapping_engine.setConfig(MappingMuseums)
|
|
||||||
}else if (engine_conf_choice == 'MappingRouenPAV') {
|
|
||||||
Mapping_engine.setConfig(MappingRouenPAV)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Mapping_engine.setConfig(mappingConfigIRVE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let currentMappingConfig = Mapping_engine.getConfig();
|
|
||||||
convertDataFromSource(sourceFilePathGeoJson, currentMappingConfig, pointCounterMax, boundingBoxCoordinates)
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
// choisir la config IRVE par défaut si aucune option de config de mapping n'est choisie en CLI
|
||||||
|
|
||||||
console.log(' ------ on utilise mappingConfigIRVE_simple')
|
|
||||||
let mappingConfigIRVE = mappingConfigIRVE_simple
|
if (engine_conf_choice !== default_engine_conf_choice && allowed_configs.indexOf("mappingIssy2Roues") !== -1) {
|
||||||
convertDataFromSource(sourceFilePathGeoJson, mappingConfigIRVE, pointCounterMax, boundingBoxCoordinates)
|
// ['mappingIssy2Roues', 'mappingConfigIRVE', 'mappingConfigIRVEFromOsmose', 'mappingConfigIRVE_simple', 'mappingTest', 'ConfigIRVE']
|
||||||
|
if (engine_conf_choice == 'mappingIssy2Roues') {
|
||||||
|
console.log('mappingIssy2Roues', mappingIssy2Roues)
|
||||||
|
Mapping_engine.setConfig(mappingIssy2Roues)
|
||||||
|
} else if (engine_conf_choice == 'mappingConfigIRVE') {
|
||||||
|
Mapping_engine.setConfig(mappingConfigIRVE)
|
||||||
|
} else if (engine_conf_choice == 'mappingConfigIRVEFromOsmose') {
|
||||||
|
Mapping_engine.setConfig(mappingConfigIRVEFromOsmose)
|
||||||
|
} else if (engine_conf_choice == 'mappingConfigIRVE_simple') {
|
||||||
|
Mapping_engine.setConfig(mappingConfigIRVE_simple)
|
||||||
|
} else if (engine_conf_choice == 'mappingTest') {
|
||||||
|
Mapping_engine.setConfig(mappingTest)
|
||||||
|
} else if (engine_conf_choice == 'ConfigIRVE') {
|
||||||
|
Mapping_engine.setConfig(ConfigIRVE)
|
||||||
|
} else if (engine_conf_choice == 'mappingRouenParkingVelos') {
|
||||||
|
Mapping_engine.setConfig(mappingRouenParkingVelos)
|
||||||
|
} else if (engine_conf_choice == 'MappingArbresIssy') {
|
||||||
|
Mapping_engine.setConfig(MappingArbresIssy)
|
||||||
|
} else if (engine_conf_choice == 'mappingFINESS') {
|
||||||
|
Mapping_engine.setConfig(mappingFINESS)
|
||||||
|
} else if (engine_conf_choice == 'MappingArbres92') {
|
||||||
|
Mapping_engine.setConfig(MappingArbres92)
|
||||||
|
} else if (engine_conf_choice == 'MappingMuseums') {
|
||||||
|
Mapping_engine.setConfig(MappingMuseums)
|
||||||
|
} else if (engine_conf_choice == 'MappingRouenPAV') {
|
||||||
|
Mapping_engine.setConfig(MappingRouenPAV)
|
||||||
|
} else if (engine_conf_choice == 'MappingAskAngela') {
|
||||||
|
Mapping_engine.setConfig(MappingAskAngela)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Mapping_engine.setConfig(mappingConfigIRVE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
let currentMappingConfig = Mapping_engine.getConfig();
|
||||||
|
convertDataFromSource(sourceFilePathGeoJson, currentMappingConfig, pointCounterMax, boundingBoxCoordinates)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
console.log(' ------ on utilise mappingConfigIRVE_simple')
|
||||||
|
let mappingConfigIRVE = mappingConfigIRVE_simple
|
||||||
|
convertDataFromSource(sourceFilePathGeoJson, mappingConfigIRVE, pointCounterMax, boundingBoxCoordinates)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,7 +421,7 @@ function setMappingConfigFromName(engine_conf_choice: string) {
|
|||||||
* Launch conversion of dataset
|
* Launch conversion of dataset
|
||||||
*/
|
*/
|
||||||
function init() {
|
function init() {
|
||||||
setMappingConfigFromName(engine_conf_choice)
|
setMappingConfigFromName(engine_conf_choice)
|
||||||
}
|
}
|
||||||
|
|
||||||
init()
|
init()
|
||||||
|
13
docs/ask_angela.md
Normal file
13
docs/ask_angela.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Ask Angela, dispositif anti harcèlement
|
||||||
|
Les commerces et autres lieux adhérant au dispositif
|
||||||
|
|
||||||
|
# Conversion
|
||||||
|
## Conversion des données de Toulouse
|
||||||
|
```bash
|
||||||
|
ts-node convert_to_osm_tags.ts --source=etalab_data/ask_angela/toulouse_askangela.json --output-file=toulouse_askangela.json --engine-config=MappingAskAngela
|
||||||
|
```
|
||||||
|
|
||||||
|
## Conversion des données de Bordeaux
|
||||||
|
```bash
|
||||||
|
ts-node convert_to_osm_tags.ts --source=etalab_data/ask_angela/bordeaux_askangela.json --output-file=bordeaux_askangela.json --engine-config=MappingAskAngela
|
||||||
|
```
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
60
mappings/converters/configAskAngela.ts
Normal file
60
mappings/converters/configAskAngela.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/**
|
||||||
|
* commerces adhérant à Ask Angela
|
||||||
|
* https://wiki.openstreetmap.org/wiki/FR:Tag:harassment_prevention%3Dask_angela
|
||||||
|
*/
|
||||||
|
import MappingConfigType from "../mapping-config.type";
|
||||||
|
|
||||||
|
const MappingAskAngela: MappingConfigType = {
|
||||||
|
config_name: "mappingRouenParkingVelos",
|
||||||
|
config_author: "tykayn <contact@cipherbliss.com>",
|
||||||
|
default_properties_of_point: {
|
||||||
|
'harassment_prevention': 'ask_angela',
|
||||||
|
},
|
||||||
|
source: {
|
||||||
|
geojson_path: '',
|
||||||
|
url: ''
|
||||||
|
},
|
||||||
|
filters: {
|
||||||
|
// exclude_point_if_tag_not_empty: ['id_osm'], // on peut exclure des données converties celles qui sont déjà avec un identifiant openstreetmap afin de favoriser l'intégration san avoir à gérer les doublons
|
||||||
|
// offset: 50
|
||||||
|
},
|
||||||
|
add_not_mapped_tags_too: false,
|
||||||
|
boolean_keys: [],
|
||||||
|
tags_to_ignore_if_value_is: ['Non renseigne'],
|
||||||
|
tags: {
|
||||||
|
// ******* opendata de toulouse START **************
|
||||||
|
structure: {
|
||||||
|
remove_original_key: true,
|
||||||
|
conditional_values: {
|
||||||
|
"Hôtel": {
|
||||||
|
tags_to_add: {
|
||||||
|
'tourism': 'hotel'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Restaurant": {
|
||||||
|
tags_to_add: {
|
||||||
|
'amenity': 'restaurant'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'id': 'ref:FR:Toulouse:ask_angela_id',
|
||||||
|
noms: 'name',
|
||||||
|
// ******* opendata de toulouse END **************
|
||||||
|
// ******* opendata de poitiers START **************
|
||||||
|
'_id': 'ref:FR:Poitiers:ask_angela_id',
|
||||||
|
// ******* opendata de poitiers END **************
|
||||||
|
|
||||||
|
|
||||||
|
// ******* opendata de bordeaux START **************
|
||||||
|
'gid': 'ref:FR:Bordeaux:ask_angela_id',
|
||||||
|
'libelle': 'name',
|
||||||
|
'url': 'contact:website',
|
||||||
|
'cdate': 'start_date:ask_angela',
|
||||||
|
'mdate': 'check_date:ask_angela',
|
||||||
|
// ******* opendata de bordeaux END **************
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MappingAskAngela;
|
Loading…
Reference in New Issue
Block a user