return new GeometryCollection(null, factory == null ? new GeometryFactory() : factory);
/** * 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); }
public GeometryCollection createGeometryCollection() { return new GeometryCollection(null, this); }
protected GeometryCollection copyInternal() { Geometry[] geometries = new Geometry[this.geometries.length]; for (int i = 0; i < geometries.length; i++) { geometries[i] = this.geometries[i].copy(); } return new GeometryCollection(geometries, factory); }
@Test public void testSkipEmptyGeometryCollections() throws Exception { ReferencedEnvelope world = new ReferencedEnvelope(160, 180, -40, 40, WGS84); ReferencedEnvelope mercatorEnvelope = world.transform(MERCATOR, true); // move it so that it crosses the dateline (measures are still accurate for something // crossing the dateline mercatorEnvelope.translate(mercatorEnvelope.getWidth() / 2, 0); // a geometry that will cross the dateline and sitting in the same area as the // rendering envelope Geometry g1 = new WKTReader() .read( "POLYGON((150 40, 150 -90, 190 -90, 190 40, 175 40, 175 -87, 165 -87, 165 40, 150 40))"); // Empty geometry collection Geometry collection = new GeometryCollection(null, g1.getFactory()); // make sure the geometry is not wrapped ProjectionHandler handler = new ProjectionHandler( WGS84, new Envelope(-0.5d, 2.0d, -0.5d, 2.0d), mercatorEnvelope); assertTrue(handler.requiresProcessing(collection)); Geometry preProcessed = handler.preProcess(collection); // Ensure something has changed assertNotEquals(collection, preProcessed); // Ensure the result is null assertNull(preProcessed); }
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 void testGeometryCollection() throws Exception { PrecisionModel precisionModel = new PrecisionModel(); int SRID = 4326; GeometryFactory gf = new GeometryFactory(precisionModel, SRID); Coordinate[] points = {new Coordinate(30, 40), new Coordinate(50, 60)}; LineString[] geometries = new LineString[2]; geometries[0] = gf.createLineString(points); Coordinate[] points2 = {new Coordinate(40, 30), new Coordinate(70, 40)}; geometries[1] = gf.createLineString(points2); GeometryFactory factory = new GeometryFactory(); GeometryCollection geometry = new GeometryCollection(geometries, factory); FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); PropertyName p = ff.property(aname("geom")); Literal collect = ff.literal(geometry); DWithin dwithinGeomCo = ((FilterFactory2) ff).dwithin(p, collect, 5, "meter"); Query dq = new Query(tname("road"), dwithinGeomCo); SimpleFeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(dq); assertEquals(0, features.size()); } }