From 85eb60333a514305f68c96f60d85136a2802a344 Mon Sep 17 00:00:00 2001 From: SebF Date: Sat, 9 Oct 2021 20:47:09 +0200 Subject: [PATCH] =?UTF-8?q?d=C3=A9placement=20de=20la=20m=C3=A9thode=20de?= =?UTF-8?q?=20nettoyage=20json=20avec=20les=20m=C3=A9thodes=20de=20sauvega?= =?UTF-8?q?rde?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- osm_vc63/save.py | 42 +++++++++++++++++++++++++++++++++++ recup_donnees_OSM_Overpass.py | 37 +----------------------------- 2 files changed, 43 insertions(+), 36 deletions(-) diff --git a/osm_vc63/save.py b/osm_vc63/save.py index b4c5426..7334f6c 100644 --- a/osm_vc63/save.py +++ b/osm_vc63/save.py @@ -46,3 +46,45 @@ class Save: jsonFile.close() print("Sauvegarde résultat format JSON/OSM " + nom_req) + + def nettoyage_json_pour_umap(self, data, overpass_query_fields): + """Sélection uniquement des champs export_json == oui""" + + export_json = { + "version": data["version"], + "generator": data["generator"] + " and ETALAB API", + "osm3s": data["osm3s"], + "elements": [], + } + + index_line = 0 + + for element in data["elements"]: + export_json["elements"].append( + {"type": element["type"], "id": element["id"]} + ) + + # positionnement des éléments + if element["type"] == "node": # noeuds + export_json["elements"][index_line]["lat"] = element["lat"] + export_json["elements"][index_line]["lon"] = element["lon"] + else: # ways et relations + export_json["elements"][index_line]["center"] = element["center"] + export_json["elements"][index_line]["nodes"] = element["nodes"] + + # filtrage des tags + description = "" + for tag in overpass_query_fields.keys(): + if overpass_query_fields[tag]["export_json"] == "Oui": + if tag in element["tags"]: + if overpass_query_fields[tag]["FR"] != "": + description = ( + description + overpass_query_fields[tag]["FR"] + " : " + ) + + description = description + str(element["tags"][tag]) + "\n" + export_json["elements"][index_line]["tags"] = {"description": description} + + index_line = index_line + 1 + + return export_json diff --git a/recup_donnees_OSM_Overpass.py b/recup_donnees_OSM_Overpass.py index a112edf..6fabed2 100644 --- a/recup_donnees_OSM_Overpass.py +++ b/recup_donnees_OSM_Overpass.py @@ -70,41 +70,6 @@ trad_bicycle_parking = { "handlebar_holder": "Accroche-guidons"} -def nettoyage_json_pour_umap(data, overpass_query_fields): - export_json = {"version": data["version"], - "generator" : data["generator"] + " and ETALAB API", - "osm3s" : data["osm3s"], - "elements": [] - } - - index_line = 0 - - for element in data["elements"]: - export_json["elements"].append({"type" : element["type"], - "id" : element["id"]}) - - # positionnement des éléments - if (element["type"] == "node") : # noeuds - export_json["elements"][index_line]["lat"] = element["lat"] - export_json["elements"][index_line]["lon"] = element["lon"] - else : # ways et relations - export_json["elements"][index_line]["center"] = element["center"] - export_json["elements"][index_line]["nodes"] = element["nodes"] - - # filtrage des tags - description = "" - for tag in overpass_query_fields.keys() : - if overpass_query_fields[tag]["export_json"] == "Oui" : - if tag in element["tags"] : - if overpass_query_fields[tag]["FR"] != "" : - description = description + overpass_query_fields[tag]["FR"] + " : " - - description = description + str(element["tags"][tag]) + "\n" - export_json["elements"][index_line]["tags"] = {"description": description} - - index_line = index_line + 1 - - return export_json def run_overpass_query(critere, aire_de_recherche) : @@ -196,7 +161,7 @@ def executer_requete_et_exporter_resultats(nom_req, critere, aire_de_recherche, print() """ - export_json = nettoyage_json_pour_umap(data, overpass_query_fields) + export_json = Save().nettoyage_json_pour_umap(data, overpass_query_fields) # Sauvegarde os.makedirs(dossier_sauvegarde, exist_ok = True)