forked from Olav63/outils_OSM
extraction du nettoyage du JSON pour export
This commit is contained in:
parent
a78342fe73
commit
f97ffdb6d9
@ -107,6 +107,45 @@ def sauvegarde_json(export_json, dossier, nom_req):
|
||||
jsonFile.write(json.dumps(export_json))
|
||||
jsonFile.close()
|
||||
|
||||
print("Sauvegarde résultat format JSON/OSM " + nom_req)
|
||||
|
||||
|
||||
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(query) :
|
||||
"""Envoie la requête Overpass et retourne la réponse JSON."""
|
||||
@ -202,48 +241,7 @@ def executer_requete_et_exporter_resultats(nom_req, critere, aire_de_recherche,
|
||||
print()
|
||||
"""
|
||||
|
||||
print("Sauvegarde résultat format JSON/OSM")
|
||||
|
||||
export_json = {"version": data["version"],
|
||||
"generator" : data["generator"] + " and ETALAB API",
|
||||
"osm3s" : data["osm3s"],
|
||||
"elements": []
|
||||
}
|
||||
|
||||
index_line = 0
|
||||
|
||||
# on refait un JSON allégé juste avec les données qu'on va afficher sur la carte UMAP
|
||||
|
||||
for element in data["elements"]:
|
||||
|
||||
export_json["elements"].append({"type" : element["type"],
|
||||
"id" : element["id"]})
|
||||
|
||||
if (element["type"] == "node") :
|
||||
export_json["elements"][index_line]["lat"] = element["lat"]
|
||||
export_json["elements"][index_line]["lon"] = element["lon"]
|
||||
else :
|
||||
export_json["elements"][index_line]["center"] = element["center"]
|
||||
export_json["elements"][index_line]["nodes"] = element["nodes"]
|
||||
|
||||
#export_json["elements"][index_line]["tags"] = element["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
|
||||
|
||||
export_json = nettoyage_json_pour_umap(data, overpass_query_fields)
|
||||
|
||||
# Sauvegarde
|
||||
os.makedirs(dossier_sauvegarde, exist_ok = True)
|
||||
|
Loading…
Reference in New Issue
Block a user