admin管理员组文章数量:1357562
I am retrieving a List<Coordinate>
from an external source, and it is known to contain one or more polygons.
Here's an example of the coordinates. As you can see, it contains two squares which do not overlap and are also not adjacent.
(0, 0)
(0, 5)
(5, 5)
(5, 0)
(0, 0)
(12, 12)
(12, 17)
(17, 17)
(17, 12)
(12, 12)
Now how do I get polygons from a list of coordinates? Of course, I could traverse all coordinates manually and check if they are a closed ring, but is there a more elegant way?
I've tried to look at the methods of GeometryFactory
and Geometry
, but I couldn't find anything similar to what I'm trying to achieve.
Note: one may assume that the received coordinates always represent a sequence of polygons without holes.
I am retrieving a List<Coordinate>
from an external source, and it is known to contain one or more polygons.
Here's an example of the coordinates. As you can see, it contains two squares which do not overlap and are also not adjacent.
(0, 0)
(0, 5)
(5, 5)
(5, 0)
(0, 0)
(12, 12)
(12, 17)
(17, 17)
(17, 12)
(12, 12)
Now how do I get polygons from a list of coordinates? Of course, I could traverse all coordinates manually and check if they are a closed ring, but is there a more elegant way?
I've tried to look at the methods of GeometryFactory
and Geometry
, but I couldn't find anything similar to what I'm trying to achieve.
Note: one may assume that the received coordinates always represent a sequence of polygons without holes.
Share Improve this question edited Mar 31 at 13:26 MC Emperor asked Mar 31 at 8:22 MC EmperorMC Emperor 23.1k16 gold badges88 silver badges137 bronze badges 1- Is the specified example list one sequence of 10 coordinates from which 2 polygons should result? If so, in general, will the sequence always be grouped as depicted (i.e. 1 subsequence per geometry)?. – Computable Commented Mar 31 at 13:04
1 Answer
Reset to default 0In JTS, a Polygon consists of an outer shell and inner holes. Both are represented as LinearRings.
Depending on the situation, you could represent those coordinates using different geometries (e.g., two Polygons, a MultiPolygon, or a GeometryCollection).
From the two lists of coordinates, which in your case make up a closed LinearRings (that's good, we need that!).
A
LinearRing
is aLineString
which is both closed and simple. In other words, the first and last coordinate in the ring must be equal, and the ring must not self-intersect.
With the GeometryFactory, you were on the right track. There is the method geometryFactory.createPolygon(coordinates),
that you could use to construct the polygons, but first, you would need to build each JTS Coordinate var c = new Coordinate(x, y)
.
本文标签:
版权声明:本文标题:java - How to get polygons from a list of Coordinates with JTS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743960383a2568914.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论