多边形与线串的交点(闭合曲线)
我有一个多边形,例如
polygon_coords = [(-13585557.004033158, 4498795.070440721), (-13585215.14187693, 4500515.198409752), (-13581108.78850055, 4497863.34704348), (-13581192.612077117, 4497554.426176021), (-13580596.94148188, 4497528.496299017), (-13580385.211810393, 4497383.150012096), (-13579492.874772193, 4497412.443364113), (-13579516.36318475, 4497381.46809963), (-13579512.689641556, 4496699.194502575), (-13579497.884149278, 4495658.910722646), (-13579543.747779485, 4495404.005766705), (-13579528.051731283, 4493390.628219194), (-13581939.67717983, 4494259.602208199), (-13585136.884274904, 4495136.215086736), (-13585127.088159712, 4495209.923404868), (-13585108.943082713, 4497557.089248097), (-13585088.237657426, 4497826.48350398), (-13584837.546164159, 4498714.608439874), (-13585109.833638642, 4498744.185863254), (-13585477.18795826, 4498785.958859128), (-13585557.004033158, 4498795.070440721)]
polygon = Polygon(polygon_coords)
line_coords = [(-13581392.216297297, 4494641.272566045), (-13581395.793280436, 4494647.557676422)]
list(polygon.intersection(LineString(line_coords)).coords)
>>> [(-13581392.216297297, 4494641.272566045), (-13581395.793280436, 4494647.557676422)]
list(polygon.intersection(LineString(line_coords + [line_coords[0]])).coords)
>>> [(-13581392.216297297, 4494641.272566045), (-13581395.793280436, 4494647.557676422)]
LineString(line_coords)
和 LineString(line_coords + [line_coords[0]])
的交集给出相同的结果。我期待交叉路口有所有坐标。我错过了什么吗?
I have a polygon as such
polygon_coords = [(-13585557.004033158, 4498795.070440721), (-13585215.14187693, 4500515.198409752), (-13581108.78850055, 4497863.34704348), (-13581192.612077117, 4497554.426176021), (-13580596.94148188, 4497528.496299017), (-13580385.211810393, 4497383.150012096), (-13579492.874772193, 4497412.443364113), (-13579516.36318475, 4497381.46809963), (-13579512.689641556, 4496699.194502575), (-13579497.884149278, 4495658.910722646), (-13579543.747779485, 4495404.005766705), (-13579528.051731283, 4493390.628219194), (-13581939.67717983, 4494259.602208199), (-13585136.884274904, 4495136.215086736), (-13585127.088159712, 4495209.923404868), (-13585108.943082713, 4497557.089248097), (-13585088.237657426, 4497826.48350398), (-13584837.546164159, 4498714.608439874), (-13585109.833638642, 4498744.185863254), (-13585477.18795826, 4498785.958859128), (-13585557.004033158, 4498795.070440721)]
polygon = Polygon(polygon_coords)
line_coords = [(-13581392.216297297, 4494641.272566045), (-13581395.793280436, 4494647.557676422)]
list(polygon.intersection(LineString(line_coords)).coords)
>>> [(-13581392.216297297, 4494641.272566045), (-13581395.793280436, 4494647.557676422)]
list(polygon.intersection(LineString(line_coords + [line_coords[0]])).coords)
>>> [(-13581392.216297297, 4494641.272566045), (-13581395.793280436, 4494647.557676422)]
Intersection of LineString(line_coords)
and LineString(line_coords + [line_coords[0]])
gives the same result. I was expecting the intersection to have all the coordinates.. Am I missing something ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
交叉点
是一个复杂的空间操作,并且 shapely 不会返回与参数中提供的相同的对象,即使相交的对象是相同的。在这里看到 - 即使我们只是得到线与其自身的交点,shapely 也返回了一个新对象,尽管坐标相等:
由于线 (A, B, A) 的形状等同于 (A, B ),shapely 永远不会从交点返回 (A, B, A)。也没有理由不为
polygon.intersection(line)
返回 (B, A),因为交集没有方向性概念。intersection
is a complex spatial operation, and shapely does not return the same object as is provided in the arguments, even if the intersecting objects are identical.Seen here - even if we're just getting the intersection of the line with itself, shapely has returned a new object, though the coordinates are equal:
Since the line (A, B, A) is equivalent in shape to (A, B), shapely will never return (A, B, A) from the intersection. There's also no reason why it wouldn't return (B, A) for
polygon.intersection(line)
, as the intersection has no concept of directionality.