我的问题是:如何确定一个已经分割旋转的矩形几何的
对于这个问题,“左”和“右”的定义是指从节点到节点“行走”时
我已经创建了这个函数,可以将任何任意
以上的想法在这里链接的笔记本中有所说明(与上面相同的链接)。 总结一下:A面和B面是包围
注意事项:
如何成功地将A和B标记为“左”和“右”?
Aside
和Bside
哪个是任意LineString
的“左”和“右”侧,该LineString
将该几何体分割?对于这个问题,“左”和“右”的定义是指从节点到节点“行走”时
LineString
分裂器的左手和右手侧。我已经创建了这个函数,可以将任何任意
shapely
几何(非集合)分成两个部分-“左”和“右”。import shapely.geometry as geo
import shapely.ops as ops
def splitLR(geom, splitter):
"""Split a geometry into a 'left' and 'right' side using the shapely API"""
if not isinstance(splitter, geo.LineString):
raise TypeError("The splitter must be a LineString")
if not splitter.is_simple:
raise ValueError("Only simple splitter objects allowed")
if hasattr(geom, "__iter__"):
raise ValueError("Geometry collections not allowed")
geom_extents = geo.GeometryCollection([geom, splitter]).minimum_rotated_rectangle
sides = ops.split(geom_extents, splitter)
try:
Aside, Bside = sides
except TypeError:
# only 1 result - rotated rectangle wasn't split
if len(ops.split(geom,splitter)) == 1:
# geom isn't split by splitter
raise ValueError("the splitter does not appear to split the geometry")
else:
# splitter too small for algorithm
raise ValueError("the splitter must extend beyond minimum_rotated_rectangle "
"of the combined geometry")
# determine which is Lside and Rside here
Lside,Rside = get_LRsides(Aside, Bside, splitter)
return tuple(side.intersection(geom) for side in (Lside, Rside))
以上的想法在这里链接的笔记本中有所说明(与上面相同的链接)。 总结一下:A面和B面是包围
geom
几何图形和splitter
线串的minimum_rotated_rectangle
的两个面。当执行side.intersection(geom)
时,结果是原始给定几何图形geom
在该面中包含的部分。注意事项:
- 对于奇怪形状的“土豆”类型物体,这种交集可能导致一个或两个方向上出现多个对象(请参见nbviewer示例)
- 我在这里创建了自己的函数(而不是使用
ops.split
),因为ops.split
函数只返回一个“袋子”中的拆分对象,并且没有办法确定它们在哪一侧(据我所知)
get_LRsides
的调用仅执行此函数,显然是无用的:def get_LRsides(Aside, Bside, splitter):
"""Determine the 'left' and 'right' sides of an already split geometry"""
return Aside,Bside
如何成功地将A和B标记为“左”和“右”?