déplacement de la méthode de nettoyage json avec les méthodes de sauvegarde
This commit is contained in:
parent
bcb9b7e9b2
commit
85eb60333a
@ -46,3 +46,45 @@ class Save:
|
|||||||
jsonFile.close()
|
jsonFile.close()
|
||||||
|
|
||||||
print("Sauvegarde résultat format JSON/OSM " + nom_req)
|
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
|
||||||
|
@ -70,41 +70,6 @@ trad_bicycle_parking = {
|
|||||||
"handlebar_holder": "Accroche-guidons"}
|
"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) :
|
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()
|
print()
|
||||||
"""
|
"""
|
||||||
|
|
||||||
export_json = nettoyage_json_pour_umap(data, overpass_query_fields)
|
export_json = Save().nettoyage_json_pour_umap(data, overpass_query_fields)
|
||||||
|
|
||||||
# Sauvegarde
|
# Sauvegarde
|
||||||
os.makedirs(dossier_sauvegarde, exist_ok = True)
|
os.makedirs(dossier_sauvegarde, exist_ok = True)
|
||||||
|
Loading…
Reference in New Issue
Block a user