def compute_segment_geometry(feature1_wkt, feature2_wkt):
""" Returns a geometry (LineString) connecting features centers """
def mysum(x, a, b):
return [(a[i] + b[i]) * x for i in range(0, 3)]
def bary(coords):
return reduce(lambda x, y: mysum(1.0 / len(coords), x, y), coords)
geom1 = loads(feature1_wkt)
centroid1_with_z = bary(geom1.coords)
geomB = loads(feature2_wkt)
centroid2_with_z = bary(geomB.coords)
result = LineString([centroid1_with_z, centroid2_with_z])
if not result.is_valid:
raise Exception(
'Cannot compute segment geometry connecting {} and {}'.format(
feature1_wkt, feature2_wkt))
return result
评论列表
文章目录