/** * Create a new concave hull construction for the input {@link GeometryCollection}. * * @param geometries * @param threshold */ public ConcaveHull(GeometryCollection geometries, double threshold) { this.geometries = transformIntoPointGeometryCollection(geometries); this.threshold = threshold; this.geomFactory = geometries.getFactory(); }
/** * Transform into GeometryCollection. * * @param geom * input geometry * @return * a geometry collection */ private static GeometryCollection transformIntoPointGeometryCollection(GeometryCollection gc) { UniqueCoordinateArrayFilter filter = new UniqueCoordinateArrayFilter(); gc.apply(filter); Coordinate[] coord = filter.getCoordinates(); Geometry[] geometries = new Geometry[coord.length]; for (int i = 0 ; i < coord.length ; i++) { Coordinate[] c = new Coordinate[] { coord[i] }; CoordinateArraySequence cs = new CoordinateArraySequence(c); geometries[i] = new Point(cs, gc.getFactory()); } return new GeometryCollection(geometries, gc.getFactory()); }
/** * 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); } }
public GeometryCollection map(GeometryCollection gc) { List mapped = new ArrayList(); for (int i = 0; i < gc.getNumGeometries(); i++) { Geometry g = mapOp.map(gc.getGeometryN(i)); if (!g.isEmpty()) mapped.add(g); } return gc.getFactory().createGeometryCollection( GeometryFactory.toGeometryArray(mapped)); } }
/** * 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; }
/** * 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; }
/** * 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); } }
public GeometryCollection map(GeometryCollection gc) { List mapped = new ArrayList(); for (int i = 0; i < gc.getNumGeometries(); i++) { Geometry g = mapOp.map(gc.getGeometryN(i)); if (!g.isEmpty()) mapped.add(g); } return gc.getFactory().createGeometryCollection( GeometryFactory.toGeometryArray(mapped)); } }
/** * 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 = (Geometry)gc1.getGeometryN(i); List<Geometry> partial = intersection(gc2, g1); ret.addAll(partial); } return gc1.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(ret)); }
return gc.getFactory().createMultiPoint( (Point[]) result.toArray(new Point[result.size()])); } else if (gc instanceof MultiLineString) { return gc.getFactory().createMultiLineString( (LineString[]) result.toArray(new LineString[result.size()])); } else if (gc instanceof MultiPolygon) { return gc.getFactory().createMultiPolygon( (Polygon[]) result.toArray(new Polygon[result.size()])); } else { return gc.getFactory().createGeometryCollection( (Geometry[]) result.toArray(new Geometry[result.size()]));
this.geomFactory = points.getFactory();
protected static Geometry transformGeometryCollection(CoordinateTransform ct, GeometryCollection geometryCollection) throws FunctionExecutionException { Geometry[] geometry = new Geometry[geometryCollection.getNumGeometries()]; for (int i = 0; i < geometry.length; ++i) { geometry[i] = transformGeometry(ct, geometryCollection.getGeometryN(i)); } return geometryCollection.getFactory().createGeometryCollection(geometry); } }
protected static Geometry transformGeometryCollection(CoordinateTransform ct, GeometryCollection geometryCollection) throws FunctionExecutionException { Geometry[] geometry = new Geometry[geometryCollection.getNumGeometries()]; for (int i = 0; i < geometry.length; ++i) { geometry[i] = transformGeometry(ct, geometryCollection.getGeometryN(i)); } return geometryCollection.getFactory().createGeometryCollection(geometry); } }
protected static Geometry transformGeometryCollection(CoordinateTransform ct, GeometryCollection geometryCollection) throws FunctionExecutionException { Geometry[] geometry = new Geometry[geometryCollection.getNumGeometries()]; for (int i = 0; i < geometry.length; ++i) { geometry[i] = transformGeometry(ct, geometryCollection.getGeometryN(i)); } return geometryCollection.getFactory().createGeometryCollection(geometry); } }
private static MultiLineString mergeTrianglesEdges(GeometryCollection polygons) { GeometryFactory factory = polygons.getFactory(); Set<LineSegment> segments = new HashSet<LineSegment>(polygons.getNumGeometries()); SegmentMerge segmentMerge = new SegmentMerge(segments); for(int idGeom = 0; idGeom < polygons.getNumGeometries(); idGeom++) { Geometry polygonGeom = polygons.getGeometryN(idGeom); if(polygonGeom instanceof Polygon) { Polygon polygon = (Polygon)polygonGeom; segmentMerge.reset(); polygon.getExteriorRing().apply(segmentMerge); } } // Convert segments into multilinestring LineString[] lineStrings = new LineString[segments.size()]; int idLine = 0; for(LineSegment lineSegment : segments) { lineStrings[idLine++] = factory.createLineString(new Coordinate[] {lineSegment.p0, lineSegment.p1}); } segments.clear(); return factory.createMultiLineString(lineStrings); }
private static MultiLineString mergeTrianglesEdges(GeometryCollection polygons) { GeometryFactory factory = polygons.getFactory(); Set<LineSegment> segments = new HashSet<LineSegment>(polygons.getNumGeometries()); SegmentMerge segmentMerge = new SegmentMerge(segments); for(int idGeom = 0; idGeom < polygons.getNumGeometries(); idGeom++) { Geometry polygonGeom = polygons.getGeometryN(idGeom); if(polygonGeom instanceof Polygon) { Polygon polygon = (Polygon)polygonGeom; segmentMerge.reset(); polygon.getExteriorRing().apply(segmentMerge); } } // Convert segments into multilinestring LineString[] lineStrings = new LineString[segments.size()]; int idLine = 0; for(LineSegment lineSegment : segments) { lineStrings[idLine++] = factory.createLineString(new Coordinate[] {lineSegment.p0, lineSegment.p1}); } segments.clear(); return factory.createMultiLineString(lineStrings); }