@Override public boolean test(Geometry geom1, Geometry geom2) { if ( geom1 == null ) { return geom2 == null; } if ( geom1.isEmpty() ) { return geom2.isEmpty(); } if ( !equalSRID( geom1, geom2 ) ) { return false; } if ( geom1 instanceof GeometryCollection ) { if ( !( geom2 instanceof GeometryCollection ) ) { return false; } GeometryCollection expectedCollection = (GeometryCollection) geom1; GeometryCollection receivedCollection = (GeometryCollection) geom2; for ( int partIndex = 0; partIndex < expectedCollection.getNumGeometries(); partIndex++ ) { Geometry partExpected = expectedCollection.getGeometryN( partIndex ); Geometry partReceived = receivedCollection.getGeometryN( partIndex ); if ( !test( partExpected, partReceived ) ) { return false; } } return true; } else { return testSimpleGeometryEquality( geom1, geom2 ); } }
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; }
/** * Attempts to retype a geometry collection under the following circumstances, returning * null if the collection can not be retyped. * <ul> * <li>Single object collections are collapsed down to the object.</li> * <li>Homogenous collections are recast as the appropriate subclass.</li> * </ul> * * @see GeometryFactory#buildGeometry(Collection) */ private Geometry narrowCollectionIfPossible(GeometryCollection gc) { List<Geometry> geoms = new ArrayList<>(); for (int i = 0; i < gc.getNumGeometries(); i++) { geoms.add(gc.getGeometryN(i)); } Geometry result = gc.getFactory().buildGeometry(geoms); return !result.getClass().equals(GeometryCollection.class) ? result : null; }
/** * @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)); }
for (int i = geometries.getNumGeometries() - 1; i >= 0; i--) { int size = handler.getLength(geometries.getGeometryN(i)) + 8; fileLength += size; geometries.getEnvelopeInternal(), type, geometries.getNumGeometries(), fileLength);
@Test public void testCRSSimple() throws Exception { WKTReader reader = new WKTReader(); GeometryCollector collector = new GeometryCollector(); collector.setFactory(null); final Geometry p0 = reader.read("POINT(0 0)"); p0.setUserData(DefaultGeographicCRS.WGS84); collector.add(p0); final Geometry p1 = reader.read("POINT(1 1)"); collector.add(p1); p1.setUserData(DefaultGeographicCRS.WGS84); GeometryCollection result = collector.collect(); assertEquals(2, result.getNumGeometries()); assertSame(DefaultGeographicCRS.WGS84, result.getUserData()); assertSame(p0, result.getGeometryN(0)); assertSame(p1, result.getGeometryN(1)); }
private Geometry collectionClip(GeometryCollection geom) throws Exception { ArrayList<Geometry> result = new ArrayList<Geometry>(); for (int t = 0; t < geom.getNumGeometries(); t++) { Geometry g = geom.getGeometryN(0); Geometry clipped = _run(g); // gets the non-degenerative of the result if ((clipped != null) && (!clipped.isEmpty())) { result.add(clipped); } } if (result.size() == 0) { return null; } return new GeometryCollection( (Geometry[]) result.toArray(new Geometry[result.size()]), geom.getFactory()); }
public static int numGeometries(Geometry arg0) { if (!(arg0 instanceof GeometryCollection)) return 0; GeometryCollection _this = (GeometryCollection) arg0; return _this.getNumGeometries(); }
@DescribeProcess( title = "Nth Geometry", description = "Returns the geometry element at a given index in a geometry collection. Indexing starts at 0." ) @DescribeResult(description = "Geometry element from the geometry collection") public static Geometry getGeometryN( @DescribeParameter(name = "geom", description = "Input geometry") GeometryCollection collection, @DescribeParameter( name = "index", description = "Index of geometry element (0 is first)" ) int index) { return collection.getGeometryN(index); }
return new GeometryCollection(null, factory == null ? new GeometryFactory() : factory);
@Test public void testCollectNone() { GeometryCollector collector = new GeometryCollector(); GeometryCollection result = collector.collect(); assertNotNull(result); assertTrue(result.isEmpty()); }
/** * Creates a {@link GeometryCollection} with * every component reversed. * The order of the components in the collection are not reversed. * * @return a {@link GeometryCollection} in the reverse order */ public Geometry reverse() { int n = geometries.length; Geometry[] revGeoms = new Geometry[n]; for (int i = 0; i < geometries.length; i++) { revGeoms[i] = geometries[i].reverse(); } return getFactory().createGeometryCollection(revGeoms); } }
@Test public void testCRSNested() throws Exception { WKTReader reader = new WKTReader(); GeometryCollector collector = new GeometryCollector(); collector.setFactory(null); final Geometry p0 = reader.read("MULTIPOINT(0 0, 1 1)"); p0.setUserData(DefaultGeographicCRS.WGS84); collector.add(p0); final Geometry p1 = reader.read("MULTIPOINT(2 2, 3 3)"); collector.add(p1); p1.setUserData(DefaultGeographicCRS.WGS84); GeometryCollection result = collector.collect(); assertEquals(4, result.getNumGeometries()); assertSame(DefaultGeographicCRS.WGS84, result.getUserData()); assertEquals(reader.read("POINT(0 0)"), result.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)); }
public static boolean isEmpty(Geometry geometry) { if (geometry.isEmpty()) { // check for case of multi geometry, if it has > 0 goemetries // we consider this to be not empty if (geometry instanceof GeometryCollection) { if (((GeometryCollection) geometry).getNumGeometries() != 0) { return false; } } return true; } return false; }
public void testBadGeometryCollection() { GeometryCollection gc = (GeometryCollection) fromWKT("GEOMETRYCOLLECTION ( POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1) )), POINT(0 0) )"); Polygon poly = (Polygon) gc.getGeometryN(0); updateNonClosedRing(poly.getInteriorRingN(0)); checkIsValid(poly, false); }
/** * Creates a GeometryCollection using the given Geometries; a null or empty * array will create an empty GeometryCollection. * * @param geometries an array of Geometries, each of which may be empty but not null, or null * @return the created GeometryCollection */ public GeometryCollection createGeometryCollection(Geometry[] geometries) { return new GeometryCollection(geometries, this); }
@Test public void testCollectNull() { GeometryCollector collector = new GeometryCollector(); collector.add(null); GeometryCollection result = collector.collect(); assertNotNull(result); assertTrue(result.isEmpty()); }
public static Geometry getGeometryN(Geometry arg0, Integer arg1) { if (!(arg0 instanceof GeometryCollection) || arg1 == null) return null; GeometryCollection _this = (GeometryCollection) arg0; if (arg1 < 0 || arg1 >= _this.getNumGeometries()) return null; return _this.getGeometryN(arg1); }
/** * Helper method for {@link #intersection(Geometry, Geometry) intersection(Geometry, Geometry)} */ private static GeometryCollection intersection(GeometryCollection gc1, GeometryCollection gc2) { List<Geometry> ret = new ArrayList<Geometry>(); final int size = gc1.getNumGeometries(); for (int i = 0; i < size; i++) { Geometry g1 = gc1.getGeometryN(i); List<Geometry> partial = intersection(gc2, g1); ret.addAll(partial); } return gc1.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(ret)); }