batch ignore points if a property is found with a certain critera of exclusion
This commit is contained in:
parent
c102c2b1ff
commit
2ff5a68998
@ -162,7 +162,7 @@ function convertDataFromSource(sourceFilePath: string, mapping: any, pointCounte
|
||||
|
||||
if (data_transformed.features) {
|
||||
|
||||
console.log('data found in source, features:', data_transformed.features.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
|
||||
@ -176,6 +176,16 @@ function convertDataFromSource(sourceFilePath: string, mapping: any, pointCounte
|
||||
list_of_points.forEach((feature_point: any) => {
|
||||
|
||||
let regex_filter_test_result = true
|
||||
let remove_original_key = false;
|
||||
feature_point.properties.tags.forEach((tagKey:string, tagValue:string)=>{
|
||||
if (this.mapping_config.filters.exclude_point_if_tag_not_empty.indexOf(tagKey) !== -1 && tagValue.length && tagValue !== 'null') {
|
||||
remove_original_key = true;
|
||||
}
|
||||
})
|
||||
if(remove_original_key){
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
if (enable_filter_on_department) {
|
||||
debugLog('filtre sur les départements activé')
|
||||
|
@ -22,3 +22,7 @@ Conversion en fichier OSM avec le paquet python pip geojson2osm:
|
||||
```shell
|
||||
geojsontoosm output/my_converted_data_set__mappingIssy2Roues.json > osm_output/issy_parkings_2r.osm
|
||||
```
|
||||
## Parking cyclables de la métropole de Rouen
|
||||
```bash
|
||||
ts-node convert_to_osm_tags.ts --source=etalab_data/cyclabilité/rouen_parking_velos.json --output-file=rouen_parking_velos.json --engine-config=mappingRouenParkingVelos
|
||||
```
|
||||
|
File diff suppressed because one or more lines are too long
@ -89,11 +89,11 @@ const MappingIRVE: MappingConfigType = {
|
||||
|
||||
// ******** champs booléens
|
||||
cable_t2_attache: {
|
||||
key_converted: 'socket:type2_cable',
|
||||
// socket:type2_cable vaut 1 dans OSM si vrai
|
||||
truthy_value: '1',
|
||||
ignore_if_falsy: true,
|
||||
}
|
||||
key_converted: 'socket:type2_cable',
|
||||
// socket:type2_cable vaut 1 dans OSM si vrai
|
||||
truthy_value: '1',
|
||||
ignore_if_falsy: true,
|
||||
}
|
||||
,
|
||||
prise_type_ef: {
|
||||
key_converted: 'socket:typee',
|
||||
@ -123,28 +123,28 @@ const MappingIRVE: MappingConfigType = {
|
||||
convert_to_boolean_value: true,
|
||||
},
|
||||
accessibilite_pmr: {
|
||||
key_converted: "wheelchair",
|
||||
conditional_values: {
|
||||
"Accessibilité inconnue": {
|
||||
ignore_this_data: true, // ne pas ajouter de tag si la valeur est égale à Accessibilité inconnue.
|
||||
},
|
||||
"Accessible mais non réservé PMR": {
|
||||
value_converted: "yes"
|
||||
},
|
||||
"Réservé PMR": {
|
||||
value_converted: "yes"
|
||||
},
|
||||
"Non accessible": {
|
||||
value_converted: "no"
|
||||
},
|
||||
"Mo-Fr 08:30-12:00,Mo-Fr 14:00-19:00,Sat 09:00-18:30": {
|
||||
value_converted: "Mo-Fr 08:30-12:00,Mo-Fr 14:00-19:00,Sat 09:00-18:30"
|
||||
},
|
||||
// On précise que l'on veut conserver cette valeur, par défaut tout ce qui n'est pas précisé en valeur conditionnelle n'est pas conservé
|
||||
"24/7": {
|
||||
value_converted: "24/7"
|
||||
}
|
||||
},
|
||||
key_converted: "wheelchair",
|
||||
conditional_values: {
|
||||
"Accessibilité inconnue": {
|
||||
ignore_this_data: true, // ne pas ajouter de tag si la valeur est égale à Accessibilité inconnue.
|
||||
},
|
||||
"Accessible mais non réservé PMR": {
|
||||
value_converted: "yes"
|
||||
},
|
||||
"Réservé PMR": {
|
||||
value_converted: "yes"
|
||||
},
|
||||
"Non accessible": {
|
||||
value_converted: "no"
|
||||
},
|
||||
"Mo-Fr 08:30-12:00,Mo-Fr 14:00-19:00,Sat 09:00-18:30": {
|
||||
value_converted: "Mo-Fr 08:30-12:00,Mo-Fr 14:00-19:00,Sat 09:00-18:30"
|
||||
},
|
||||
// On précise que l'on veut conserver cette valeur, par défaut tout ce qui n'est pas précisé en valeur conditionnelle n'est pas conservé
|
||||
"24/7": {
|
||||
value_converted: "24/7"
|
||||
}
|
||||
},
|
||||
},
|
||||
station_deux_roues: {
|
||||
remove_original_key: true,
|
||||
|
@ -16,46 +16,77 @@ const mappingRouenParkingVelos: MappingConfigType = {
|
||||
url: 'https://data.metropole-rouen-normandie.fr/api/explore/v2.1/catalog/datasets/liste-des-stationnements-cyclables-metropole-rouen-normandie/exports/geojson?lang=fr&timezone=Europe%2FBerlin'
|
||||
},
|
||||
filters: {
|
||||
exclude_point_if_tag_not_empty: ['osm_id']
|
||||
},
|
||||
add_not_mapped_tags_too: false,
|
||||
boolean_keys: [
|
||||
"acces_reglement",
|
||||
],
|
||||
tags_to_ignore_if_value_is: ['Non renseigne'],
|
||||
tags: {
|
||||
// ******* nombres
|
||||
nb_places: 'capacity',
|
||||
nb_pl_velo: 'capacity:bike',
|
||||
nb_pl_moto: 'capacity:motorcycle',
|
||||
annee_crea: 'start_date',
|
||||
capacite: 'capacity',
|
||||
capacite_cargo: 'capacity:cargo_bike',
|
||||
gestionnaire: {
|
||||
key_converted: 'operator',
|
||||
conditionnal_values: {
|
||||
"Non renseigne": {
|
||||
ignore_this_data: true, // ne pas ajouter de tag si la valeur est égale à
|
||||
}
|
||||
}
|
||||
},
|
||||
proprietaire: {
|
||||
key_converted: 'owner',
|
||||
conditionnal_values: {
|
||||
"Non renseigne": {
|
||||
ignore_this_data: true, // ne pas ajouter de tag si la valeur est égale à
|
||||
}
|
||||
}
|
||||
},
|
||||
date_maj: 'check_date',
|
||||
// ******* textes
|
||||
type_aire: {
|
||||
"remove_original_key": true,
|
||||
"conditional_values": {
|
||||
"Poteaux": {
|
||||
commentaire: 'note',
|
||||
surveillance: {
|
||||
key_converted: 'surveillance',
|
||||
ignore_if_falsy: true,
|
||||
convert_to_boolean_value: true,
|
||||
},
|
||||
mobilier: {
|
||||
key_converted: 'mobilier',
|
||||
remove_original_key: true,
|
||||
conditional_values: {
|
||||
"POTELET": {
|
||||
"tags_to_add": [
|
||||
{
|
||||
"bicycle_parking": "bollard"
|
||||
},
|
||||
]
|
||||
]
|
||||
},
|
||||
"Arceaux": {
|
||||
"tags_to_add": [
|
||||
{
|
||||
"bicycle_parking": "bollard"
|
||||
},
|
||||
]
|
||||
},
|
||||
"Anneaux": {
|
||||
"ARCEAU": {
|
||||
"tags_to_add": [
|
||||
{
|
||||
"bicycle_parking": "stands"
|
||||
},
|
||||
]
|
||||
]
|
||||
},
|
||||
"RATELIER": {
|
||||
"tags_to_add": [
|
||||
{
|
||||
"bicycle_parking": "rack"
|
||||
},
|
||||
]
|
||||
},
|
||||
// "Anneaux": {
|
||||
// "tags_to_add": [
|
||||
// {
|
||||
// "bicycle_parking": "stands"
|
||||
// },
|
||||
// ]
|
||||
// },
|
||||
}
|
||||
},
|
||||
// type_aire: 'nb_pl_moto', // Poteaux => bicycle_parking=bollard, Arceaux, Anneaux => bicycle_parking=stands, Marquage, null, Non renseigné, Range-vélos, Sans, Trottoir
|
||||
id_r2roues: 'ref:FR:rouen_veloparking_id',
|
||||
id_local: 'ref:FR:rouen_veloparking_id',
|
||||
// acces_reglement: 'access',
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,10 @@ const MappingTest: MappingConfigType = {
|
||||
nom_amenageur : 'name'
|
||||
},
|
||||
add_not_mapped_tags_too: false,
|
||||
source: {},
|
||||
source: {
|
||||
geojson_path: "",
|
||||
url: ""
|
||||
},
|
||||
filters: {},
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import custom_utils from './utils'
|
||||
import MappingConfigType from "./mapping-config.type";
|
||||
import {debuglog} from "util";
|
||||
|
||||
const {debugLog} = custom_utils
|
||||
|
||||
@ -139,7 +138,9 @@ export default class {
|
||||
|
||||
debugLog('mapElementFromConf: convert', pointKeyName)
|
||||
debugLog('mapElementFromConf: mapping keys:', mappingKeys)
|
||||
this.convertProperty(pointKeyName, mappingKeys, featurePoint, newProperties)
|
||||
|
||||
this.convertProperty(pointKeyName, mappingKeys, featurePoint, newProperties)
|
||||
|
||||
|
||||
})
|
||||
|
||||
@ -178,6 +179,12 @@ export default class {
|
||||
debugLog(' ------ convertProperty: pointKeyName', pointKeyName)
|
||||
// debugLog('convertProperty: mappingKeys', mappingKeys)
|
||||
|
||||
let remove_original_key = false;
|
||||
if (this.mapping_config.tags_to_ignore_if_value_is.indexOf(originalValue) !== -1) {
|
||||
remove_original_key = true;
|
||||
}
|
||||
|
||||
|
||||
if (this.jardinage) {
|
||||
debugLog(' ------ on fait du jardinage')
|
||||
debugLog(' ------ mode mise en qualité activé')
|
||||
@ -240,12 +247,14 @@ export default class {
|
||||
debugLog('convertProperty: no string value')
|
||||
}
|
||||
|
||||
let configObject = mappingConfigOfTag
|
||||
|
||||
if (isConfigMappingObject) {
|
||||
let configObject = mappingConfigOfTag
|
||||
|
||||
|
||||
debugLog('convertProperty: is config object', configObject)
|
||||
let newKey: any = '' + pointKeyName
|
||||
let remove_original_key = false;
|
||||
|
||||
|
||||
if (configObject.key_converted) {
|
||||
newKey = configObject.key_converted
|
||||
|
@ -1,75 +1,96 @@
|
||||
interface GeoJsonGeometry {
|
||||
type:string,
|
||||
coordinates:Array<number>,
|
||||
type: string,
|
||||
coordinates: Array<number>,
|
||||
}
|
||||
|
||||
interface GeoJsonProperties {
|
||||
[key:string]: any,
|
||||
[key: string]: any,
|
||||
}
|
||||
|
||||
interface GeoJsonFeature {
|
||||
type:string,
|
||||
geometry:GeoJsonGeometry,
|
||||
properties:GeoJsonProperties,
|
||||
type: string,
|
||||
geometry: GeoJsonGeometry,
|
||||
properties: GeoJsonProperties,
|
||||
}
|
||||
|
||||
export interface FeatureCollection{
|
||||
type:string,
|
||||
features:Array<GeoJsonFeature>,
|
||||
export interface FeatureCollection {
|
||||
type: string,
|
||||
features: Array<GeoJsonFeature>,
|
||||
}
|
||||
|
||||
export interface BoundingBoxCoordinatesType{
|
||||
export interface BoundingBoxCoordinatesType {
|
||||
xMin: number,
|
||||
xMax: number,
|
||||
yMin: number,
|
||||
yMax: number,
|
||||
}
|
||||
export default interface MappingConfigType{
|
||||
|
||||
/**
|
||||
* configuration to choose what point to exclude or include from geographic or properties hints
|
||||
*/
|
||||
export interface filteringConfig {
|
||||
enable_coordinates_filter?: boolean;
|
||||
enable_properties_filter?: boolean;
|
||||
properties?: object;
|
||||
bounding_box?: object;
|
||||
exclude_point_if_tag_not_empty?: Array<string>;
|
||||
exclude_point_if_tag_truthy?: Array<string>;
|
||||
exclude_point_if_tag_falsy?: Array<string>;
|
||||
}
|
||||
|
||||
interface sourceConfig {
|
||||
geojson_path: string; // the relative path to the geojson source file to analyse, from the root of this repository
|
||||
url: string; // URL from where the geojson comes online, on a data platform. This URL should be fetchable to get the most recent data of the concerned dataset to convert.
|
||||
}
|
||||
|
||||
export default interface MappingConfigType {
|
||||
config_name: string,
|
||||
config_author: string,
|
||||
osmose?: boolean,
|
||||
boolean_keys?: Array<string>,
|
||||
tags_to_ignore_if_value_is?: Array<string>,
|
||||
add_not_mapped_tags_too: boolean,
|
||||
default_properties_of_point: object,
|
||||
source: object,
|
||||
filters: object,
|
||||
default_properties_of_point?: object, // tag to add to every converted point by default
|
||||
source: sourceConfig,
|
||||
filters?: filteringConfig,
|
||||
tags: FeaturePropertyMappingConfigType
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* configuration concernant toutes les valeurs
|
||||
*/
|
||||
export interface FeaturePropertyMappingConfigType{
|
||||
[key:string]: any,
|
||||
convert_to_boolean_value?:boolean,
|
||||
remove_original_key?:boolean,
|
||||
conditionnal_values?:ConditionnalValuesType,
|
||||
transform_function?:Function,
|
||||
export interface FeaturePropertyMappingConfigType {
|
||||
[key: string]: any,
|
||||
|
||||
convert_to_boolean_value?: boolean,
|
||||
remove_original_key?: boolean,
|
||||
conditionnal_values?: ConditionnalValuesType,
|
||||
transform_function?: Function,
|
||||
}
|
||||
|
||||
/**
|
||||
* choix de conversion de la valeur originale selon des critères donnés
|
||||
*/
|
||||
export interface ConditionnalValuesConfigType{
|
||||
key_converted?:string,
|
||||
value_converted?:string,
|
||||
truthy_value?:any,
|
||||
falsy_value?:any, // si la valeur originale est falsy, la convertir en la valeur donnée ici
|
||||
ignore_this_data?:boolean,
|
||||
tags_to_add?:TagsToAddConfig,
|
||||
transform_function?:Function,
|
||||
export interface ConditionnalValuesConfigType {
|
||||
key_converted?: string,
|
||||
value_converted?: string,
|
||||
truthy_value?: any,
|
||||
falsy_value?: any, // si la valeur originale est falsy, la convertir en la valeur donnée ici
|
||||
ignore_this_data?: boolean,
|
||||
tags_to_add?: TagsToAddConfig,
|
||||
transform_function?: Function,
|
||||
}
|
||||
|
||||
export interface ConditionnalValuesType{
|
||||
[key:string]: ConditionnalValuesConfigType,
|
||||
export interface ConditionnalValuesType {
|
||||
[key: string]: ConditionnalValuesConfigType,
|
||||
}
|
||||
|
||||
interface OneOSMTag {
|
||||
[key:string]: string,
|
||||
[key: string]: string,
|
||||
}
|
||||
|
||||
export interface TagsToAddConfig{
|
||||
export interface TagsToAddConfig {
|
||||
tags_to_add: Array<OneOSMTag>
|
||||
}
|
||||
|
||||
|
17828
output/my_converted_data_set__mappingRouenParkingVelos.json
Normal file
17828
output/my_converted_data_set__mappingRouenParkingVelos.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user