/** * @param gc * @param at */ public void init( GeometryCollection gc, AffineTransform at, boolean generalize, double maxDistance) { this.gc = gc; this.at = at == null ? new AffineTransform() : at; this.generalize = generalize; this.maxDistance = maxDistance; currentGeom = 0; done = false; currentIterator = gc.isEmpty() ? EmptyIterator.INSTANCE : getIterator(gc.getGeometryN(0)); }
/** * Converts a <code>GeometryCollection</code> to <GeometryCollectionText> format, then * appends it to the writer. * * @param geometryCollection the <code>GeometryCollection</code> to process * @param writer the output writer to append to */ private void appendGeometryCollectionText( GeometryCollection geometryCollection, int level, Writer writer) throws IOException { if (geometryCollection.isEmpty()) { writer.write("EMPTY"); } else { int level2 = level; writer.write("("); for (int i = 0; i < geometryCollection.getNumGeometries(); i++) { if (i > 0) { writer.write(", "); level2 = level + 1; } appendGeometryTaggedText(geometryCollection.getGeometryN(i), level2, writer); } writer.write(")"); } }
Geometry widestGeometry(GeometryCollection gc) { if (gc.isEmpty()) { return gc; } Geometry widest = gc.getGeometryN(0); for (int i = 1; i < gc.getNumGeometries(); i++) { Geometry curr = gc.getGeometryN(i); if (curr.getEnvelopeInternal().getWidth() > widest.getEnvelopeInternal().getWidth()) { widest = curr; } } return widest; }
@Test public void testCollectNone() { GeometryCollector collector = new GeometryCollector(); GeometryCollection result = collector.collect(); assertNotNull(result); assertTrue(result.isEmpty()); }
@Test public void testCollectNull() { GeometryCollector collector = new GeometryCollector(); collector.add(null); GeometryCollection result = collector.collect(); assertNotNull(result); assertTrue(result.isEmpty()); }
public Coordinate getCoordinate() { if (isEmpty()) return null; return geometries[0].getCoordinate(); }
/** * @param gc * @param at */ public void init(GeometryCollection gc, AffineTransform at) { this.gc = gc; this.at = at == null ? new AffineTransform() : at; currentGeom = 0; done = false; currentIterator = gc.isEmpty() ? EmptyIterator.INSTANCE : getIterator(gc.getGeometryN(0)); }
/** * @param gc * @param at */ public void init(GeometryCollection gc, AffineTransform at) { this.gc = gc; this.at = at == null ? new AffineTransform() : at; currentGeom = 0; done = false; currentIterator = gc.isEmpty() ? EmptyIterator.INSTANCE : getIterator(gc.getGeometryN(0)); }
/** * @param gc * @param at */ public void init(GeometryCollection gc, AffineTransform at) { this.gc = gc; this.at = at == null ? new AffineTransform() : at; currentGeom = 0; done = false; currentIterator = gc.isEmpty() ? EmptyIterator.INSTANCE : getIterator(gc.getGeometryN(0)); }
throws IOException if (geometryCollection.isEmpty()) { writer.write("EMPTY");
private Geometry widestGeometry(GeometryCollection gc) { if (gc.isEmpty()) { return gc; } Geometry widestGeometry = gc.getGeometryN(0); // scan remaining geom components to see if any are wider for (int i = 1; i < gc.getNumGeometries(); i++) { if (gc.getGeometryN(i).getEnvelopeInternal().getWidth() > widestGeometry.getEnvelopeInternal().getWidth()) { widestGeometry = gc.getGeometryN(i); } } return widestGeometry; }
public void testReadGeometryCollection() throws Exception { // arrange double[][] coordinates = new double[][] { new double[] {10, 10}, new double[] {30, 30}, new double[] {15, 15, 20, 20}, new double[0], new double[] {10, 10, 20, 20, 30, 40, 10, 10} }; CoordinateSequence[] css = new CoordinateSequence[] { createSequence(Ordinate.createXY(), coordinates[0]), createSequence(Ordinate.createXY(), coordinates[1]), createSequence(Ordinate.createXY(), coordinates[2]), createSequence(Ordinate.createXY(), coordinates[3]), createSequence(Ordinate.createXY(), coordinates[4]), }; // arrange WKTReader rdr = GeometryTestCase.getWKTReader(Ordinate.createXY(), 1); GeometryCollection gc0 = (GeometryCollection)rdr.read("GEOMETRYCOLLECTION (POINT (10 10), POINT (30 30), LINESTRING (15 15, 20 20))"); GeometryCollection gc1 = (GeometryCollection)rdr.read("GEOMETRYCOLLECTION (POINT (10 10), LINEARRING EMPTY, LINESTRING (15 15, 20 20))"); GeometryCollection gc2 = (GeometryCollection)rdr.read("GEOMETRYCOLLECTION (POINT (10 10), LINEARRING (10 10, 20 20, 30 40, 10 10), LINESTRING (15 15, 20 20))"); GeometryCollection gc3 = (GeometryCollection)rdr.read("GEOMETRYCOLLECTION EMPTY"); // assert assertTrue(GeometryTestCase.checkEqual(css[0], ((Point)gc0.getGeometryN(0)).getCoordinateSequence())); assertTrue(GeometryTestCase.checkEqual(css[1], ((Point)gc0.getGeometryN(1)).getCoordinateSequence())); assertTrue(GeometryTestCase.checkEqual(css[2], ((LineString)gc0.getGeometryN(2)).getCoordinateSequence())); assertTrue(GeometryTestCase.checkEqual(css[0], ((Point)gc1.getGeometryN(0)).getCoordinateSequence())); assertTrue(GeometryTestCase.checkEqual(css[3], ((LinearRing)gc1.getGeometryN(1)).getCoordinateSequence())); assertTrue(GeometryTestCase.checkEqual(css[2], ((LineString)gc1.getGeometryN(2)).getCoordinateSequence())); assertTrue(GeometryTestCase.checkEqual(css[0], ((Point)gc2.getGeometryN(0)).getCoordinateSequence())); assertTrue(GeometryTestCase.checkEqual(css[4], ((LinearRing)gc2.getGeometryN(1)).getCoordinateSequence())); assertTrue(GeometryTestCase.checkEqual(css[2], ((LineString)gc2.getGeometryN(2)).getCoordinateSequence())); assertTrue(gc3.isEmpty()); }