在 Jupyter 中绘制由点覆盖的匀称线串

问题描述 投票:0回答:1

我正在尝试在线字符串上显示点以调试同一行上是否有多个点:

def to_shapely(points: list[point]):
    return shapely.ops.unary_union([
        shapely.geometry.LineString(points),
        shapely.geometry.MultiPoint(points)
    ])

to_shapely([(0,0), (2,2), (1,0.5)])

但这仅显示线串。有没有办法将点叠加在线串上?

python jupyter-notebook shapely
1个回答
0
投票

IIUC,您想要一个

GeometryCollection
而不是
unary_union
(返回单个几何图形):

import shapely

def to_shapely(points):
    return shapely.geometry.GeometryCollection([
        shapely.geometry.LineString(points),
        shapely.geometry.MultiPoint(points)
    ])

to_shapely([(0,0), (2,2), (1,0.5)])

输出:

© www.soinside.com 2019 - 2024. All rights reserved.