开发者

How to repair a polygon with self-intersection?

Is there a way to rem开发者_开发知识库ove self-intersections from a polygon using GEOS?


So, I have to answer the question myself. Maybe it will help someone.

You can repair a polygon using the geos::operation::buffer::BufferOp class. E.g.

geos::geom::Geometry * result = 
                       geos::operation::buffer::BufferOp::bufferOp(polygon, 1.0);

You can find some more good recipes in the Secrets of the JTS Topology Suite.


Often point intersections are allowed, so you can change

1  2   4
*--*   *       
|   \ /|
|    X |
|   / \|
*--*   *
6  5   3

to

1  2   4
*--*   *       
|   \ /|
|   3*6|
|   / \|
*--*   *
8  7   5

where points 3 and 6 are the same. If point intersections are not allowed, move one of them a small amount.

In my experience, most such intersections some from a faulty polygon simplification, so it would be better to go back to the source if possible.


Self-intersected polygon is invalid. Thus BufferOp may give invalid result. I didn't find any way to fix self-intersected polygon in geos. st_makevalid function in PostGIS uses geos. So it is possible to investigate the source code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜