/** * Collects all coordinates of all subgeometries into an Array. * * Note that while changes to the coordinate objects themselves * may modify the Geometries in place, the returned Array as such * is only a temporary container which is not synchronized back. * * @return the collected coordinates * */ public Coordinate[] getCoordinates() { Coordinate[] coordinates = new Coordinate[getNumPoints()]; int k = -1; for (int i = 0; i < geometries.length; i++) { Coordinate[] childCoordinates = geometries[i].getCoordinates(); for (int j = 0; j < childCoordinates.length; j++) { k++; coordinates[k] = childCoordinates[j]; } } return coordinates; }
public void testGetCoordinates() throws Exception { GeometryCollection g = (GeometryCollection) reader.read("GEOMETRYCOLLECTION (POINT (10 10), POINT (30 30), LINESTRING (15 15, 20 20))"); Coordinate[] coordinates = g.getCoordinates(); assertEquals(4, g.getNumPoints()); assertEquals(4, coordinates.length); assertEquals(new Coordinate(10, 10), coordinates[0]); assertEquals(new Coordinate(20, 20), coordinates[3]); }