musées mapping, fix key_converted and convert_to_phone bug
This commit is contained in:
parent
f566d06027
commit
1ff9c66c81
@ -16,16 +16,17 @@ import mappingRouenParkingVelos from "./mappings/converters/configRouen_OpenData
|
|||||||
import mappingFINESS from "./mappings/converters/configFINESS";
|
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";
|
||||||
|
|
||||||
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',
|
'MappingArbres92', 'MappingMuseums'
|
||||||
];
|
];
|
||||||
|
|
||||||
const minimist = require('minimist')
|
import minimist = require('minimist')
|
||||||
|
|
||||||
const debugLog = utils.debugLog;
|
const debugLog = utils.debugLog;
|
||||||
|
|
||||||
@ -391,6 +392,8 @@ function setMappingConfigFromName(engine_conf_choice: string) {
|
|||||||
Mapping_engine.setConfig(mappingFINESS)
|
Mapping_engine.setConfig(mappingFINESS)
|
||||||
} else if (engine_conf_choice == 'MappingArbres92') {
|
} else if (engine_conf_choice == 'MappingArbres92') {
|
||||||
Mapping_engine.setConfig(MappingArbres92)
|
Mapping_engine.setConfig(MappingArbres92)
|
||||||
|
} else if (engine_conf_choice == 'MappingMuseums') {
|
||||||
|
Mapping_engine.setConfig(MappingMuseums)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Mapping_engine.setConfig(mappingConfigIRVE)
|
Mapping_engine.setConfig(mappingConfigIRVE)
|
||||||
|
@ -14,7 +14,14 @@ Des jeux de données sont disponibles pour lister les abres, suivre leur évolut
|
|||||||
- FORME: tree_shape = curtain / free / half_free <= Architecturé, rideau / Libre / Semi-libre
|
- FORME: tree_shape = curtain / free / half_free <= Architecturé, rideau / Libre / Semi-libre
|
||||||
|
|
||||||
# conversion
|
# conversion
|
||||||
|
Abres d'issy les moulineaux
|
||||||
```bash
|
```bash
|
||||||
ts-node convert_to_osm_tags.ts --source=etalab_data/arbres/arbres_issy.geojson --output-file=arbres_issy.geojson --engine-config=MappingArbresIssy
|
ts-node convert_to_osm_tags.ts --source=etalab_data/arbres/arbres_issy.geojson --output-file=arbres_issy.geojson --engine-config=MappingArbresIssy
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Cadastre vert:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ts-node convert_to_osm_t
|
||||||
|
ags.ts --source=etalab_data/arbres/arbres_92.json --output-file=arbres_92.geojson --engine-config=MappingArbres92
|
||||||
|
```
|
||||||
|
7
docs/musées.md
Normal file
7
docs/musées.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# musées
|
||||||
|
|
||||||
|
Jeu de données des musées en île de france.
|
||||||
|
# conversion
|
||||||
|
```bash
|
||||||
|
ts-node convert_to_osm_tags.ts --source=etalab_data/arbres/musées/fr.geojson --output-file=musées_idf.geojson --engine-config=MappingMuseums
|
||||||
|
```
|
32
mappings/converters/configMuseums.ts
Normal file
32
mappings/converters/configMuseums.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import MappingConfigType from "../mapping-config.type";
|
||||||
|
|
||||||
|
const MappingMuseums: MappingConfigType = {
|
||||||
|
config_name: 'Mapping des musées en Île de France',
|
||||||
|
config_author: 'tykayn <contact+geojson2osm@cipherbliss.com>',
|
||||||
|
default_properties_of_point: {tourism: 'museum'},
|
||||||
|
tags: {
|
||||||
|
// ******* booléens
|
||||||
|
// ******* nombres
|
||||||
|
"URL": "contact:website",
|
||||||
|
"Identifiant Muséofile": "ref:FR:museums:museofile",
|
||||||
|
"REF_Deps": "ref:FR:museums:deps",
|
||||||
|
// ******* textes
|
||||||
|
'Téléphone': {
|
||||||
|
key_converted: "contact:phone",
|
||||||
|
convert_to_phone: true,
|
||||||
|
},
|
||||||
|
"Nom officiel du musée": {
|
||||||
|
key_converted: "name",
|
||||||
|
convert_to_name: true,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
add_not_mapped_tags_too: false,
|
||||||
|
source: {
|
||||||
|
geojson_path: '',
|
||||||
|
url: ''
|
||||||
|
},
|
||||||
|
filters: {
|
||||||
|
// offset:2 // uncomment to run small tests
|
||||||
|
},
|
||||||
|
}
|
||||||
|
export default MappingMuseums
|
@ -41,7 +41,7 @@ export default class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setConfig(mappingConfig: MappingConfigType) {
|
setConfig(mappingConfig: MappingConfigType) {
|
||||||
console.log('load config', mappingConfig.config_name)
|
debugLog('load config', mappingConfig.config_name)
|
||||||
debugLog('load config', mappingConfig.config_name)
|
debugLog('load config', mappingConfig.config_name)
|
||||||
this.mapping_config = mappingConfig
|
this.mapping_config = mappingConfig
|
||||||
}
|
}
|
||||||
@ -108,15 +108,15 @@ export default class {
|
|||||||
* @param list
|
* @param list
|
||||||
* @param excludedKeys
|
* @param excludedKeys
|
||||||
*/
|
*/
|
||||||
filterListOfPointsByExcludingIfKeyFilled(list: any, excludedKeys: Array<string>):any[] {
|
filterListOfPointsByExcludingIfKeyFilled(list: any, excludedKeys: Array<string>): any[] {
|
||||||
let newList: Array<any> = []
|
let newList: Array<any> = []
|
||||||
list.forEach((geojsonPoint: any) => {
|
list.forEach((geojsonPoint: any) => {
|
||||||
let pointProperties = Object.keys(geojsonPoint.properties)
|
let pointProperties = Object.keys(geojsonPoint.properties)
|
||||||
let addPoint = true;
|
let addPoint = true;
|
||||||
excludedKeys.forEach((key: any) => {
|
excludedKeys.forEach((key: any) => {
|
||||||
debugLog(key, 'pointProperties[key]', pointProperties[key])
|
debugLog(key, 'pointProperties[key]', pointProperties[key])
|
||||||
let foundProperty:string = pointProperties[key]
|
let foundProperty: string = pointProperties[key]
|
||||||
if ( foundProperty && foundProperty !== 'null') {
|
if (foundProperty && foundProperty !== 'null') {
|
||||||
addPoint = false
|
addPoint = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -213,9 +213,11 @@ export default class {
|
|||||||
// debugLog('convertProperty: mappingKeys', mappingKeys)
|
// debugLog('convertProperty: mappingKeys', mappingKeys)
|
||||||
|
|
||||||
let remove_original_key = false;
|
let remove_original_key = false;
|
||||||
if (this.mapping_config.tags_to_ignore_if_value_is?.indexOf(originalValue) !== -1) {
|
debugLog('tags_to_ignore_if_value_is', this.mapping_config.tags_to_ignore_if_value_is)
|
||||||
|
if (this.mapping_config.tags_to_ignore_if_value_is && this.mapping_config.tags_to_ignore_if_value_is.length && this.mapping_config.tags_to_ignore_if_value_is?.indexOf(originalValue) !== -1) {
|
||||||
debugLog('(x) => ignore', originalValue, ' in ', pointKeyName)
|
debugLog('(x) => ignore', originalValue, ' in ', pointKeyName)
|
||||||
remove_original_key = true;
|
remove_original_key = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -293,6 +295,7 @@ export default class {
|
|||||||
|
|
||||||
if (configObject.key_converted) {
|
if (configObject.key_converted) {
|
||||||
newKey = configObject.key_converted
|
newKey = configObject.key_converted
|
||||||
|
debugLog('key_converted newKey', newKey)
|
||||||
}
|
}
|
||||||
if (configObject.transform_function) {
|
if (configObject.transform_function) {
|
||||||
convertedValue = configObject.transform_function(originalValue)
|
convertedValue = configObject.transform_function(originalValue)
|
||||||
@ -414,7 +417,6 @@ export default class {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debugLog('no sockets', this.current_geojson_point.properties.ref)
|
debugLog('no sockets', this.current_geojson_point.properties.ref)
|
||||||
// console.log('sockets', countOfSockets, this.current_geojson_point.properties)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
@ -434,8 +436,8 @@ export default class {
|
|||||||
this.stats.phones_updated_list.push(convertedValue)
|
this.stats.phones_updated_list.push(convertedValue)
|
||||||
} else {
|
} else {
|
||||||
this.stats.phones_not_updated++
|
this.stats.phones_not_updated++
|
||||||
|
|
||||||
}
|
}
|
||||||
|
debugLog('convertedValue convert_to_phone', originalValue ,'=>', convertedValue)
|
||||||
|
|
||||||
}
|
}
|
||||||
if (configObject.convert_to_name) {
|
if (configObject.convert_to_name) {
|
||||||
@ -457,9 +459,8 @@ export default class {
|
|||||||
if (configObject.conditional_values) {
|
if (configObject.conditional_values) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// convert numbers from json to string to compare them correctly
|
// convert numbers from json to string to compare them correctly
|
||||||
originalValue = ''+originalValue
|
originalValue = '' + originalValue
|
||||||
|
|
||||||
let keysConditionnalValues: any = Object.keys(configObject.conditional_values)
|
let keysConditionnalValues: any = Object.keys(configObject.conditional_values)
|
||||||
let isFoundValue = keysConditionnalValues.indexOf(originalValue)
|
let isFoundValue = keysConditionnalValues.indexOf(originalValue)
|
||||||
@ -477,7 +478,7 @@ export default class {
|
|||||||
|
|
||||||
|
|
||||||
if (isFoundValue !== -1) {
|
if (isFoundValue !== -1) {
|
||||||
debugLog('found condition',isFoundValue )
|
debugLog('found condition', isFoundValue)
|
||||||
|
|
||||||
/** ----------------------
|
/** ----------------------
|
||||||
* gestion des valeurs conditionnelles
|
* gestion des valeurs conditionnelles
|
||||||
@ -518,7 +519,7 @@ export default class {
|
|||||||
// on peut définir un ensemble de tags à rajouter
|
// on peut définir un ensemble de tags à rajouter
|
||||||
let tagKeys = Object.keys(conditionnalConfig.tags_to_add)
|
let tagKeys = Object.keys(conditionnalConfig.tags_to_add)
|
||||||
debugLog('conditionnalConfig.tags_to_add', conditionnalConfig.tags_to_add)
|
debugLog('conditionnalConfig.tags_to_add', conditionnalConfig.tags_to_add)
|
||||||
tagKeys.forEach((index:any) => {
|
tagKeys.forEach((index: any) => {
|
||||||
debugLog('key', index)
|
debugLog('key', index)
|
||||||
debugLog('value', conditionnalConfig.tags_to_add[index])
|
debugLog('value', conditionnalConfig.tags_to_add[index])
|
||||||
newProperties[index] = conditionnalConfig.tags_to_add[index]
|
newProperties[index] = conditionnalConfig.tags_to_add[index]
|
||||||
@ -530,7 +531,19 @@ export default class {
|
|||||||
|
|
||||||
debugLog('convertProperty: convertedValue ==========> {', newKey, ':', convertedValue, '}')
|
debugLog('convertProperty: convertedValue ==========> {', newKey, ':', convertedValue, '}')
|
||||||
debugLog(' =============== remove_original_key', newKey, remove_original_key)
|
debugLog(' =============== remove_original_key', newKey, remove_original_key)
|
||||||
if (!remove_original_key && newKey && convertedValue && !configObject.ignore_this_data) {
|
|
||||||
|
let keysOfConfigObject = [];
|
||||||
|
let hasKeyIgnoreThisData = false;
|
||||||
|
if (configObject) {
|
||||||
|
keysOfConfigObject = Object.keys(configObject)
|
||||||
|
debugLog('keysOfConfigObject', keysOfConfigObject)
|
||||||
|
hasKeyIgnoreThisData = (keysOfConfigObject.indexOf('ignore_this_data') !== -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
debugLog('remove_original_key && newKey && convertedValue && hasKeyIgnoreThisData', remove_original_key , newKey , convertedValue ,hasKeyIgnoreThisData)
|
||||||
|
if (!remove_original_key && newKey && convertedValue && !hasKeyIgnoreThisData
|
||||||
|
) {
|
||||||
|
debugLog('convertedValue', convertedValue)
|
||||||
|
|
||||||
debugLog('convertProperty: added', newKey, (`${convertedValue}`).trim())
|
debugLog('convertProperty: added', newKey, (`${convertedValue}`).trim())
|
||||||
newProperties[newKey] = (`${convertedValue}`).trim()
|
newProperties[newKey] = (`${convertedValue}`).trim()
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
import custom_utils from "./utils";
|
import custom_utils from "./utils";
|
||||||
|
|
||||||
const {debugLog} = custom_utils
|
const {debugLog,prefix_phone_fr_only} = custom_utils
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that helps to convert values into predefined formats
|
* Class that helps to convert values into predefined formats
|
||||||
*/
|
*/
|
||||||
export default class Formatters {
|
export default class Formatters {
|
||||||
|
|
||||||
static convertToPhone(originalValue: string) {
|
static convertToPhone(originalValue: string) :string{
|
||||||
/**
|
/**
|
||||||
* nettoyer les numéros de téléphone en ne gardant que les nombres et le préfixe de pays
|
* nettoyer les numéros de téléphone en ne gardant que les nombres et le préfixe de pays
|
||||||
*/
|
*/
|
||||||
|
debugLog("convertToPhone:" , originalValue);
|
||||||
// debugLog('originalValue', originalValue.substring(1))
|
// debugLog('originalValue', originalValue.substring(1))
|
||||||
if (!originalValue) {
|
if (!originalValue) {
|
||||||
originalValue = ''
|
originalValue = ''
|
||||||
}
|
}
|
||||||
let original_without_spaces = originalValue.replace(/ /g, '')
|
let original_without_spaces = originalValue.replace(' ', '')
|
||||||
let cleaned_value = `${original_without_spaces}`
|
let cleaned_value = `${original_without_spaces}`
|
||||||
cleaned_value = cleaned_value
|
cleaned_value = cleaned_value
|
||||||
.trim()
|
.trim()
|
||||||
@ -31,6 +32,8 @@ export default class Formatters {
|
|||||||
}
|
}
|
||||||
cleaned_value = cleaned_value.replace('+33', '')
|
cleaned_value = cleaned_value.replace('+33', '')
|
||||||
|
|
||||||
|
debugLog("convertToPhone: cleaned_value" , cleaned_value);
|
||||||
|
|
||||||
if (/^0/.test(cleaned_value)) {
|
if (/^0/.test(cleaned_value)) {
|
||||||
cleaned_value = cleaned_value.substring(1)
|
cleaned_value = cleaned_value.substring(1)
|
||||||
}
|
}
|
||||||
@ -60,14 +63,14 @@ export default class Formatters {
|
|||||||
) {
|
) {
|
||||||
add_prefix = true
|
add_prefix = true
|
||||||
}
|
}
|
||||||
if (add_prefix) {
|
if (add_prefix && prefix_phone_fr_only) {
|
||||||
convertedValue = `+33 ` + convertedValue
|
convertedValue = `+33 ` + convertedValue
|
||||||
}
|
}
|
||||||
|
|
||||||
debugLog('phone: ', originalValue, '=>', convertedValue)
|
debugLog('phone: ', originalValue, '=>', convertedValue)
|
||||||
|
|
||||||
|
|
||||||
return "";
|
return ""+convertedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
static convertToName(originalValue: string) {
|
static convertToName(originalValue: string) {
|
||||||
|
@ -3,6 +3,7 @@ import * as fs from 'node:fs'
|
|||||||
let show_debug = 0
|
let show_debug = 0
|
||||||
// show_debug = 1
|
// show_debug = 1
|
||||||
let output_folder = 'output';
|
let output_folder = 'output';
|
||||||
|
const prefix_phone_fr_only = true
|
||||||
|
|
||||||
// console.log('----------------------show_debug', show_debug)
|
// console.log('----------------------show_debug', show_debug)
|
||||||
|
|
||||||
@ -72,5 +73,6 @@ function writeFile(fileName: string, fileContent: any, outputPathOverride: strin
|
|||||||
export default {
|
export default {
|
||||||
debugLog,
|
debugLog,
|
||||||
isBooleanKey,
|
isBooleanKey,
|
||||||
writeFile
|
writeFile,
|
||||||
|
prefix_phone_fr_only
|
||||||
}
|
}
|
||||||
|
21755
output/___MappingMuseums.geojson
Normal file
21755
output/___MappingMuseums.geojson
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user