mejoras
This commit is contained in:
@@ -40,7 +40,70 @@ from PVPlantResources import DirIcons as DirIcons
|
||||
import PVPlantSite
|
||||
|
||||
|
||||
def get_elevation_from_oe(coordinates): # v1 deepseek
|
||||
"""Obtiene elevaciones de Open-Elevation API y devuelve vectores FreeCAD en coordenadas UTM.
|
||||
Args:
|
||||
coordinates (list): Lista de tuplas con coordenadas (latitud, longitud)
|
||||
Returns:
|
||||
list: Lista de vectores FreeCAD con coordenadas UTM y elevación (en milímetros)
|
||||
o lista vacía en caso de error.
|
||||
"""
|
||||
if not coordinates:
|
||||
return []
|
||||
|
||||
import requests
|
||||
import utm
|
||||
from requests.exceptions import RequestException
|
||||
|
||||
# Construcción más eficiente de parámetros
|
||||
locations = "|".join([f"{lat:.6f},{lon:.6f}" for lat, lon in coordinates])
|
||||
|
||||
try:
|
||||
response = requests.get(
|
||||
url="https://api.open-elevation.com/api/v1/lookup",
|
||||
params={'locations': locations},
|
||||
timeout=20,
|
||||
verify=True
|
||||
)
|
||||
response.raise_for_status() # Lanza excepción para códigos 4xx/5xx
|
||||
|
||||
except RequestException as e:
|
||||
print(f"Error en la solicitud: {str(e)}")
|
||||
return []
|
||||
|
||||
try:
|
||||
data = response.json()
|
||||
except ValueError:
|
||||
print("Respuesta JSON inválida")
|
||||
return []
|
||||
|
||||
if "results" not in data or len(data["results"]) != len(coordinates):
|
||||
print("Formato de respuesta inesperado")
|
||||
return []
|
||||
|
||||
points = []
|
||||
for result in data["results"]:
|
||||
try:
|
||||
# Conversión UTM con manejo de errores
|
||||
easting, northing, _, _ = utm.from_latlon(
|
||||
result["latitude"],
|
||||
result["longitude"]
|
||||
)
|
||||
|
||||
points.append(FreeCAD.Vector(round(easting), # Convertir metros a milímetros
|
||||
round(northing),
|
||||
round(result["elevation"])) * 1000)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error procesando coordenadas: {str(e)}")
|
||||
continue
|
||||
|
||||
return points
|
||||
|
||||
def getElevationFromOE(coordinates):
|
||||
"""Obtiene elevaciones de Open-Elevation API y devuelve vectores FreeCAD en coordenadas UTM."""
|
||||
|
||||
from requests.exceptions import RequestException
|
||||
if len(coordinates) == 0:
|
||||
return None
|
||||
|
||||
@@ -54,7 +117,16 @@ def getElevationFromOE(coordinates):
|
||||
if i != total:
|
||||
str += '|'
|
||||
query = 'https://api.open-elevation.com/api/v1/lookup?locations=' + str
|
||||
r = get(query, timeout=20)
|
||||
try:
|
||||
r = get(query, timeout=20, verify=False)
|
||||
except RequestException as e:
|
||||
points = []
|
||||
for i, point in enumerate(coordinates):
|
||||
c = utm.from_latlon(point[0], point[1])
|
||||
points.append(FreeCAD.Vector(round(c[0] * 1000, 0),
|
||||
round(c[1] * 1000, 0),
|
||||
0))
|
||||
return points
|
||||
|
||||
# Only get the json response in case of 200 or 201
|
||||
points = []
|
||||
@@ -82,7 +154,7 @@ def getSinglePointElevationFromBing(lat, lng):
|
||||
# +# to do: error handling - wait and try again
|
||||
s = json.loads(ans)
|
||||
res = s['resourceSets'][0]['resources'][0]['elevations']
|
||||
|
||||
|
||||
import utm
|
||||
for elevation in res:
|
||||
c = utm.from_latlon(lat, lng)
|
||||
|
||||
Reference in New Issue
Block a user