在 JTS 中使用 LineString 分割多边形

发布于 2024-10-01 10:10:08 字数 125 浏览 0 评论 0原文

我有一个多边形和一条线段,其端点位于多边形的两侧。将多边形分成两个多边形的最简单方法是什么? (我正在使用 jts 包)。

我尝试过使用多边形转换器,但我认为我没有正确使用它,因为它似乎不起作用。

谢谢,

I have a polygon and a line segment which has its endpoints on two sides of the polygon. What is the easiest way to split the polygon into two polygons. (I am using the jts package).

I have tried using polygonizer but I don't think that I am using it correctly because it doesn't seem to be working.

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

她如夕阳 2024-10-08 10:10:08

迟到的答案,但也许有人也想知道这一点。

假设您有以下几何形状:
几何集合(多边形 ((100 150, 100 340, 350 340, 350 150, 100 150)),
LINESTRING (220 340, 220 150))

您可以尝试行合并此几何集合,结果应该是:
多线 ((220 340, 220 150),
(100 150, 100 340, 350 340, 350 150, 100 150))

从这里做一元并集,结果是:
多线 ((220 340, 220 150),
(100 150, 100 340, 220 340),
(220 340, 350 340, 350 150, 220 150),
(220 150, 100 150))

最后您可以使用多边形器并获得两个多边形:
几何集合(多边形 ((220 150, 220 340, 350 340, 350 150, 220 150)),
POLYGON ((100 150, 100 340, 220 340, 220 150, 100 150)))

因此要让多边形器工作,你必须给他单个线串作为输入,而不是整个多边形。

在 JTS testbuilder 中测试

Late answer but perhaps someone wants to know this too.

Assuming you have following geometry:
GEOMETRYCOLLECTION (POLYGON ((100 150, 100 340, 350 340, 350 150, 100 150)),
LINESTRING (220 340, 220 150))

You could try line merge this geometry collection, result should be:
MULTILINESTRING ((220 340, 220 150),
(100 150, 100 340, 350 340, 350 150, 100 150))

From here do an unary union, result is:
MULTILINESTRING ((220 340, 220 150),
(100 150, 100 340, 220 340),
(220 340, 350 340, 350 150, 220 150),
(220 150, 100 150))

Finally you can use the polygonizer and get the two polygons:
GEOMETRYCOLLECTION (POLYGON ((220 150, 220 340, 350 340, 350 150, 220 150)),
POLYGON ((100 150, 100 340, 220 340, 220 150, 100 150)))

So to get the polygonizer working you have to give him single linestrings as input and not a whole polygon.

Tested in JTS testbuilder

不奢求什么 2024-10-08 10:10:08

我通过将线段作为一个非常大的多边形的一部分,然后使两个多边形相交来完成类似的事情。您可以通过向线段的每一端添加线段直到超出多边形边界来创建大多边形,然后以 90 度添加超出原始多边形边界的两个线段,然后将最后两个线段与用于制作大多边形的最终线段,该多边形沿着原始线段分割原始多边形并包围原始多边形的其余部分。这相当痛苦但有效。
吉姆

I have done similar things by making the line segement part of a very large polygon and then intersect the two polygons. You can make the large polygon by adding segements to each end of the segement until you are outside the bounds of the polygon, then add two segements at 90 degrees that go beyond the bounds of the original polygon, and then link the last two segments with a final segement to make a big polygon that splits the original poylgon along the original segement and surrounds the rest of the original polygon. It's rather a pain but works.
Jim

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