public static int numGeometries(Geometry arg0) { if (!(arg0 instanceof GeometryCollection)) return 0; GeometryCollection _this = (GeometryCollection) arg0; return _this.getNumGeometries(); }
@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 ); } }
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; }
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; } }
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; }
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); }
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; } }
/** 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; }
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); } }
/** * 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)); }
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); } } }
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; }
@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); } }
public void testParse() throws Exception { GML3MockData.multiGeometry(document, document); GeometryCollection multiGeom = (GeometryCollection) parse(); assertNotNull(multiGeom); assertEquals(3, multiGeom.getNumGeometries()); }
public void testParse() throws Exception { GML3MockData.multiGeometry(document, document); GeometryCollection multiGeom = (GeometryCollection) parse(); assertNotNull(multiGeom); assertEquals(3, multiGeom.getNumGeometries()); }