多边形与线串的交点(闭合曲线)

发布于 2025-01-15 11:46:18 字数 1539 浏览 2 评论 0原文

我有一个多边形,例如

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哭了丶谁疼 2025-01-22 11:46:18

交叉点是一个复杂的空间操作,并且 shapely 不会返回与参数中提供的相同的对象,即使相交的对象是相同的。

在这里看到 - 即使我们只是得到线与其自身的交点,shapely 也返回了一个新对象,尽管坐标相等:

In [13]: line = LineString(line_coords)

In [14]: hex(id(line))
Out[14]: '0x1041f1a50'

In [15]: hex(id(line.intersection(line)))
Out[15]: '0x10569b9d0'

In [16]: line == line.intersection(line)
Out[16]: True

由于线 (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:

In [13]: line = LineString(line_coords)

In [14]: hex(id(line))
Out[14]: '0x1041f1a50'

In [15]: hex(id(line.intersection(line)))
Out[15]: '0x10569b9d0'

In [16]: line == line.intersection(line)
Out[16]: True

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文