/** */ public static Geometry flatten (GeometryCollection gc) { final List<Point> points = new LinkedList<Point>(); final List<LineString> lines = new LinkedList<LineString>(); final List<Polygon> polygons = new LinkedList<Polygon>(); gc.apply(new GeometryFilter() { public void filter (Geometry geom) { if (geom instanceof Point) { points.add((Point)geom); } else if (geom instanceof LineString) { lines.add((LineString)geom); } else if (geom instanceof Polygon) { polygons.add((Polygon)geom); } } }); if (!polygons.isEmpty()) { return gc.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons)); } else if (!lines.isEmpty()) { return gc.getFactory().createMultiLineString(GeometryFactory.toLineStringArray(lines)); } else { return gc.getFactory().createMultiPoint(GeometryFactory.toPointArray(points)); } }
public static void applyToInnerGeometries(final Polygon g, final GeometryFilter f) { final int holes = g.getNumInteriorRing(); if (holes == 0) return; for (int i = 0; i < holes; i++) { g.getInteriorRingN(i).apply(f); } }
public static void applyToInnerGeometries(final GeometryCollection g, final GeometryFilter f) { final int geoms = g.getNumGeometries(); if (geoms == 0) return; for (int i = 0; i < geoms; i++) { final Geometry sub = g.getGeometryN(i); sub.apply(f); } }
@Override public void apply(final GeometryFilter filter) { filter.filter(this); }
void drawSimpleGeometry(final OpenGL gl, final Geometry geom) throws ExecutionException { geom.apply((GeometryFilter) (g) -> drawer.accept(g)); }
@Override public void apply(GeometryFilter filter) { // Do nothing. This circle is not expected to be a complete geometry. }
/** * Applies a GeometryComponentFilter to internal geometries. Concerns the geometries contained in multi-geometries, * and the holes in polygons. Limited to one level (i.e. holes in polygons in a MultiPolygon will not be visited) * * @param g * the geometry to visit * @param f * the filter to apply */ public static void applyToInnerGeometries(final Geometry g, final GeometryFilter f) { if (g instanceof Polygon) applyToInnerGeometries((Polygon) g, f); else if (g instanceof GeometryCollection) { applyToInnerGeometries((GeometryCollection) g, f); } }