forked from Olav63/outils_OSM
méthode d'appel csv géocodage inverse
This commit is contained in:
parent
cba94b2caa
commit
dfd8d264b4
@ -25,6 +25,7 @@ import os
|
||||
import datetime
|
||||
import shutil
|
||||
import pathlib
|
||||
import csv
|
||||
from collections import OrderedDict
|
||||
import requests
|
||||
from pyexcel_ods3 import save_data
|
||||
@ -160,6 +161,18 @@ class Utils:
|
||||
|
||||
return response.json()
|
||||
|
||||
def run_reverse_geocoding_csv(self, lat, lon):
|
||||
"""Retourne une adresse JSON à partir d'une position GPS."""
|
||||
|
||||
url = self.geo_api_url + "/reverse/"
|
||||
|
||||
response = requests.get(url, params={"lon": str(lon), "lat": str(lat)})
|
||||
|
||||
if response.status_code != 200:
|
||||
raise errors.GeoApiError(response.status_code)
|
||||
|
||||
return response.json()
|
||||
|
||||
def geocodage(self, data):
|
||||
"""Renseigne une adresse pour chaque élément de data"""
|
||||
|
||||
@ -224,6 +237,42 @@ class Utils:
|
||||
|
||||
return data
|
||||
|
||||
def geocodage_csv(self, data2):
|
||||
"""
|
||||
Renseigne une adresse pour chaque élément de data
|
||||
en une fois via csv
|
||||
"""
|
||||
|
||||
url = self.geo_api_url + "/reverse/csv/"
|
||||
|
||||
with open("output.csv", "w", newline="") as data_to_file:
|
||||
|
||||
csv_writer = csv.writer(data_to_file)
|
||||
|
||||
for element in data2["elements"]:
|
||||
if element["type"] == "node":
|
||||
csv_writer.writerow([element["lat"], element["lon"]])
|
||||
else:
|
||||
csv_writer.writerow(
|
||||
[element["center"]["lat"], element["center"]["lon"]]
|
||||
)
|
||||
|
||||
response = requests.post(
|
||||
url,
|
||||
files=OrderedDict(
|
||||
[("data", ("output.csv", open("output.csv", "rb").read()))]
|
||||
),
|
||||
)
|
||||
|
||||
if response.status_code != 200:
|
||||
raise errors.GeoApiError(response.status_code)
|
||||
|
||||
print(response)
|
||||
|
||||
logging.info("Géocodage inversé terminé")
|
||||
|
||||
return data2
|
||||
|
||||
def traduction(self, tag, dictionnaire, data):
|
||||
"""Traduit le champ tag des éléments de data avec dict"""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user