简体   繁体   中英

How to enumerate vertices in Geometry in JTS?

Java Topology Suite has Geometry class, which has getNumPoints() method. According to documentation, it counts all vertices in all constituent geometries.

How to enumerate all these points? They can be obtained by getCoordinates() method, but this looks not optimal, since (1) is not iterative and (2) requires to convert each coordinate tuple into Point by GeomertFactory .

As you probably have some proper geometry type like LineString or Polygon, use that (cast your Geometry to it), then you can use getPointN(index) .

Coordinates are not Points by the way. Coordinate is not a geometry in JTS, just a class to hold numeric values. Points are actual geometries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM