@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 ); } }
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); }
/** Wraps the elements of a geometry collection in a normal collection. */ public static Collection asCollection(GeometryCollection gc) { ArrayList members = new ArrayList(); for (int i = 0; i < gc.getNumGeometries(); i++) { members.add(gc.getGeometryN(i)); } return members; }
public Object getProperty(Object object, QName name) throws Exception { GeometryCollection gc = (GeometryCollection) object; if (KML.Geometry.getLocalPart().equals(name.getLocalPart())) { Geometry[] g = new Geometry[gc.getNumGeometries()]; for (int i = 0; i < g.length; i++) { g[i] = gc.getGeometryN(i); } return g; } return null; } }
private void flattenCollection(List<Geometry> result) { for (int i = 0; i < result.size(); ) { Geometry g = result.get(i); if (g instanceof GeometryCollection) { GeometryCollection gc = (GeometryCollection) g; for (int j = 0; j < gc.getNumGeometries(); j++) { result.add(gc.getGeometryN(j)); } result.remove(i); } else { i++; } } }
protected <T> void accumulateGeometries( List<T> collection, Geometry g, Class<? extends T> target) { if (target.isInstance(g)) { collection.add((T) g); } else if (g instanceof GeometryCollection) { GeometryCollection coll = (GeometryCollection) g; for (int i = 0; i < coll.getNumGeometries(); i++) { accumulateGeometries(collection, coll.getGeometryN(i), target); } } }
@Override public Object getProperty(Object object, QName name) throws Exception { if (GML.geometryMember.getLocalPart().equals(name.getLocalPart())) { GeometryCollection multiGeometry = (GeometryCollection) object; Geometry[] members = new Geometry[multiGeometry.getNumGeometries()]; for (int i = 0; i < members.length; i++) { members[i] = (Geometry) multiGeometry.getGeometryN(i); } GML3EncodingUtils.setChildIDs(multiGeometry); return members; } return null; } }
Map<String, Object> createGeometryCollection(GeometryCollection gcol) { LinkedHashMap obj = new LinkedHashMap(); ArrayList geoms = new ArrayList(gcol.getNumGeometries()); for (int i = 0; i < gcol.getNumGeometries(); i++) { geoms.add(create(gcol.getGeometryN(i))); } obj.put("type", "GeometryCollection"); obj.put("geometries", geoms); return obj; }
/** * @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)); }
/** Helper method for {@link #intersects(Geometry, Geometry) intersects(Geometry, Geometry)} */ private static boolean intersects(GeometryCollection gc1, GeometryCollection gc2) { final int size = gc1.getNumGeometries(); for (int i = 0; i < size; i++) { Geometry g1 = gc1.getGeometryN(i); if (intersects(gc2, g1)) return true; } return false; }
/** Helper method for {@link #intersects(Geometry, Geometry) intersects(Geometry, Geometry)} */ private static boolean intersects(GeometryCollection gc, Geometry g) { final int size = gc.getNumGeometries(); for (int i = 0; i < size; i++) { Geometry g1 = gc.getGeometryN(i); if (g1.intersects(g)) return true; } return false; }
/** * Helper method for {@link #intersection(Geometry, Geometry) intersection(Geometry, Geometry)} */ private static List<Geometry> intersection(GeometryCollection gc, Geometry g) { List<Geometry> ret = new ArrayList<Geometry>(); final int size = gc.getNumGeometries(); for (int i = 0; i < size; i++) { Geometry g1 = gc.getGeometryN(i); collect(g1.intersection(g), ret); } return ret; }
/** * 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)); }
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; }
List toList(GeometryCollection mgeom) { ArrayList list = new ArrayList(mgeom.getNumGeometries()); for (int i = 0; i < mgeom.getNumGeometries(); i++) { Geometry g = mgeom.getGeometryN(i); if (g instanceof Polygon) { list.add(toList((Polygon) g)); } else if (g instanceof LineString) { list.add( new CoordinateSequenceEncoder( ((LineString) g).getCoordinateSequence(), scale)); } else if (g instanceof Point) { list.add(new CoordinateSequenceEncoder(((Point) g).getCoordinateSequence(), scale)); } } return list; }
private static final Geometry cloneGeometry(GeometryCollection geom, int dimension) { if (geom.getNumGeometries() == 0) { Geometry[] gs = new Geometry[0]; return geomFac.createGeometryCollection(gs); } ArrayList gs = new ArrayList(geom.getNumGeometries()); int n = geom.getNumGeometries(); for (int t = 0; t < n; t++) { gs.add(cloneGeometry(geom.getGeometryN(t), dimension)); } return geomFac.buildGeometry(gs); }
private void writeMulti(GeometryCollection geometry, String member) { for (int i = 0, n = geometry.getNumGeometries(); i < n; i++) { start(member); encode(geometry.getGeometryN(i)); end(member); } } }
private void writeGeometryCollection(int geometryType, GeometryCollection gc, OutStream os) throws IOException { writeByteOrder(os); writeGeometryType(geometryType, os); writeInt(gc.getNumGeometries(), os); for (int i = 0; i < gc.getNumGeometries(); i++) { write(gc.getGeometryN(i), os); } }
@Override public void encode( GeometryCollection geometry, AttributesImpl atts, GMLWriter handler, String gmlId) throws Exception { atts = cloneWithGmlId(atts, gmlId); handler.startElement(multiGeometry, atts); for (int i = 0; i < geometry.getNumGeometries(); i++) { handler.startElement(geometryMember, null); gge.encode(geometry.getGeometryN(i), null, handler, gmlId + "." + (i + 1)); handler.endElement(geometryMember); } handler.endElement(multiGeometry); } }
@Test public void testTwo() throws Exception { WKTReader reader = new WKTReader(); GeometryCollector collector = new GeometryCollector(); collector.setFactory(null); final Geometry p0 = reader.read("POINT(0 0)"); collector.add(p0); final Geometry p1 = reader.read("POINT(1 1)"); collector.add(p1); GeometryCollection result = collector.collect(); assertEquals(2, result.getNumGeometries()); assertSame(p0, result.getGeometryN(0)); assertSame(p1, result.getGeometryN(1)); }