graph_operations.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:albion 作者: Oslandia 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号