/** * Like makeGoodShapePolygon, but applied towards a multi polygon. * * @param mp The MultiPolygon to "niceify". * @return The "nicified" MultiPolygon. */ public static final MultiPolygon makeGoodShapeMultiPolygon(MultiPolygon mp) { MultiPolygon result; Polygon[] ps = new Polygon[mp.getNumGeometries()]; // check each sub-polygon for (int t = 0; t < mp.getNumGeometries(); t++) { ps[t] = makeGoodShapePolygon((Polygon) mp.getGeometryN(t)); } result = mp.getFactory().createMultiPolygon(ps); return result; }
/** * Creates a {@link MultiPolygon} with * every component reversed. * The order of the components in the collection are not reversed. * * @return a MultiPolygon in the reverse order */ public Geometry reverse() { int n = geometries.length; Polygon[] revGeoms = new Polygon[n]; for (int i = 0; i < geometries.length; i++) { revGeoms[i] = (Polygon) geometries[i].reverse(); } return getFactory().createMultiPolygon(revGeoms); }
/** * Computes the boundary of this geometry * * @return a lineal geometry (which may be empty) * @see Geometry#getBoundary */ public Geometry getBoundary() { if (isEmpty()) { return getFactory().createMultiLineString(); } ArrayList allRings = new ArrayList(); for (int i = 0; i < geometries.length; i++) { Polygon polygon = (Polygon) geometries[i]; Geometry rings = polygon.getBoundary(); for (int j = 0; j < rings.getNumGeometries(); j++) { allRings.add(rings.getGeometryN(j)); } } LineString[] allRingsArray = new LineString[allRings.size()]; return getFactory().createMultiLineString((LineString[]) allRings.toArray(allRingsArray)); }
/** * Create a new multiPolygon without hole. * * @param multiPolygon * @return */ public static MultiPolygon removeHolesMultiPolygon(MultiPolygon multiPolygon) { int num = multiPolygon.getNumGeometries(); Polygon[] polygons = new Polygon[num]; for (int i = 0; i < num; i++) { polygons[i] = removeHolesPolygon((Polygon) multiPolygon.getGeometryN(i)); } return multiPolygon.getFactory().createMultiPolygon(polygons); }
/** * Simplifies a MultiPolygon. * <BR/><BR/> * Simplification is performed by first removing collinear points, then * by applying DouglasPeucker simplification. * <BR/>Order <B>is</B> important, since it's more likely to have collinear * points before applying any other simplification. */ public static MultiPolygon simplifyMultiPolygon(final MultiPolygon mp) { final Polygon[] simpPolys = new Polygon[mp.getNumGeometries()]; for (int i = 0; i < mp.getNumGeometries(); i++) { Polygon p = (Polygon) mp.getGeometryN(i); Polygon s1 = p; //Utils.removeCollinearVertices(p); TopologyPreservingSimplifier tps = new TopologyPreservingSimplifier(s1); Polygon s2 = (Polygon) tps.getResultGeometry(); simpPolys[i] = s2; if (LOGGER.isInfoEnabled()) { LOGGER.info("RCV: simplified poly " + getPoints(p) + " --> " + getPoints(s1) + " --> " + getPoints(s2)); } } // reuse existing factory final GeometryFactory gf = mp.getFactory(); return gf.createMultiPolygon(simpPolys); }
/** * Drape a multilinestring to a set of triangles * @param polygons * @param triangles * @param sTRtree * @return */ public static Geometry drapeMultiPolygon(MultiPolygon polygons, Geometry triangles, STRtree sTRtree) { GeometryFactory factory = polygons.getFactory(); //Split the triangles in lines to perform all intersections Geometry triangleLines = LinearComponentExtracter.getGeometry(triangles, true); int nbPolygons = polygons.getNumGeometries(); Polygon[] polygonsDiff = new Polygon[nbPolygons]; for (int i = 0; i < nbPolygons; i++) { polygonsDiff[i] = processPolygon((Polygon) polygons.getGeometryN(i), triangleLines, factory); } Geometry diffExt = factory.createMultiPolygon(polygonsDiff); CoordinateSequenceFilter drapeFilter = new DrapeFilter(sTRtree); diffExt.apply(drapeFilter); return diffExt; }