create_layer_widget.py 文件源码

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

项目:albion 作者: Oslandia 项目源码 文件源码
def substring_3d(linestring, from_, to_):
    "the linestring a shapely geometry, from_ and to_ are in length units"
    tot_len = 0
    sq = lambda x: x*x
    def interpolate(a, b, ratio):
        return (a[0] + ratio*(b[0] - a[0]), a[1] + ratio*(b[1] - a[1]), a[2] + ratio*(b[2] - a[2]))
    res = []
    for s, e in zip(linestring.coords[0:-1], linestring.coords[1:]):
        length = sqrt(sq(s[0]-e[0]) + sq(s[1]-e[1]) + sq(s[2]-e[2]))
        tot_len += length
        if tot_len > from_:
            if not len(res):
                #interpolate first
                res.append(interpolate(e, s, (tot_len - from_)/length))
            if tot_len >= to_:
                #interpolate last
                res.append(interpolate(e, s, (tot_len - to_)/length))
                break
            res.append(e)
    return LineString(res)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号