affectation des addresses obtenues

This commit is contained in:
SebF 2021-11-01 21:10:43 +01:00
parent bebc0602a9
commit 0f5bc4ba16

View File

@ -264,11 +264,43 @@ class Utils:
) )
response = requests.post(url, files=payload) response = requests.post(url, files=payload)
# nettoyage
os.remove("tmp_geocodage.csv") os.remove("tmp_geocodage.csv")
if response.status_code != 200: if response.status_code != 200:
raise errors.GeoApiError(response.status_code) raise errors.GeoApiError(response.status_code)
# affectation des addresses
for element in data["elements"]:
for row in csv.DictReader(response.text.splitlines()):
lat_ok = row["lat"] == str(element["lat"])
lon_ok = row["lon"] == str(element["lon"])
if lat_ok and lon_ok:
element["tags"]["api_adresse:geometry:coordinates:lon"] = row[
"result_longitude"
]
element["tags"]["api_adresse:geometry:coordinates:lat"] = row[
"result_latitude"
]
element["tags"]["api_adresse:properties:label"] = row[
"result_label"
]
element["tags"]["api_adresse:properties:housenumber"] = row[
"result_housenumber"
]
element["tags"]["api_adresse:properties:type"] = row["result_type"]
element["tags"]["api_adresse:properties:name"] = row["result_name"]
element["tags"]["api_adresse:properties:postcode"] = row[
"result_postcode"
]
element["tags"]["api_adresse:properties:citycode"] = row[
"result_citycode"
]
element["tags"]["api_adresse:properties:city"] = row["result_city"]
element["tags"]["api_adresse:properties:street"] = row[
"result_street"
]
logging.info("Géocodage inversé terminé") logging.info("Géocodage inversé terminé")
return data return data