def addMetricDistanceToEdge(x1,y1,x2,y2, epsgCode):
# we assume initial epsg is wsg84 (merctor projection)
if epsgCode != 4326:
sourceProjection = osr.SpatialReference()
sourceProjection.ImportFromEPSG(4326)
destinationProjection = osr.SpatialReference()
destinationProjection.ImportFromEPSG(epsgCode) # https://epsg.io/2154
coordTrans = osr.CoordinateTransformation(sourceProjection, destinationProjection)
line = ogr.Geometry(ogr.wkbLineString)
line.AddPoint(x1,y1)
line.AddPoint(x2,y2)
if epsgCode != 4326:
line.Transform(coordTrans)
length = line.Length()
return length
评论列表
文章目录