- Primera transformación de cualquier CRS en coordenadas geográficas (lon/lat o WGS 84)
- Ahora podemos obtener el identificador de zona UTM (llamado EPSG), por ejemplo 32632 (UTM zona 32N).
- Transformar de nuevo, esta vez en UTM
- Interpolar en metros :-D
- Transformar la espalda
- Transformar la espalda
Código:
import math
import shapely.geometry as sg
def get_utm_zone(longitude):
return int((math.floor((longitude + 180.0) / 6.0) + 1) % 60)
def get_epsg(longitude, latitude):
epsg = 32600
if latitude < 0.0:
epsg += 100
epsg += get_utm_zone(longitude)
return epsg
def get_point_b_between(point_a, point_c, distance_from_a_to_b):
"""
Input points as features
"""
point_a = point_a.geometry().asPoint()
point_c = point_c.geometry().asPoint()
crs_src = qgis.utils.iface.activeLayer().crs()
crs_dest = QgsCoordinateReferenceSystem(4326) # WGS 84
xform_wgs = QgsCoordinateTransform(crs_src, crs_dest)
point_a_wgs = xform_wgs.transform(QgsPoint(point_a.x(), point_a.y()))
point_c_wgs = xform_wgs.transform(QgsPoint(point_c.x(), point_c.y()))
epsg = get_epsg(point_a_wgs.x(), point_a_wgs.y())
crs_src = QgsCoordinateReferenceSystem(4326) # WGS 84
crs_dest = QgsCoordinateReferenceSystem(epsg) # UTM
xform_utm = QgsCoordinateTransform(crs_src, crs_dest)
point_a_utm = xform_utm.transform(QgsPoint(point_a_wgs.x(), point_a_wgs.y()))
point_c_utm = xform_utm.transform(QgsPoint(point_c_wgs.x(), point_c_wgs.y()))
line = sg.LineString([(point_a_utm.x(),point_a_utm.y()),(point_c_utm.x(),point_c_utm.y())])
point_b_utm = line.interpolate(distance_from_a_to_b)
point_b_wgs = xform_utm.transform(QgsPoint(point_b_utm.x, point_b_utm.y), QgsCoordinateTransform.ReverseTransform)
point_b = xform_wgs.transform(QgsPoint(point_b_wgs.x(), point_b_wgs.y()), QgsCoordinateTransform.ReverseTransform)
f = QgsFeature()
f.setGeometry(QgsGeometry.fromPoint(point_b))
return f
Crear una capa de puntos con dos características seleccionadas y entrar en la consola:
a = qgis.utils.iface.activeLayer().selectedFeatures()[0]
c = qgis.utils.iface.activeLayer().selectedFeatures()[1]
b = get_point_b_between(a,c,135.0)
Para ser optimizado...