/** * Compute the footprint. * * @param geometriesList the List of all the geometries found across the dataset * @param transform * @throws MismatchedDimensionException * @throws TransformException * @throws FactoryException */ private void computeFootprint(List<Polygon> geometriesList, MathTransform transform) throws MismatchedDimensionException, TransformException, FactoryException { // Creating the final multipolygon Polygon[] polArray = new Polygon[geometriesList.size()]; Polygon[] polygons = geometriesList.toArray(polArray); final Geometry innerGeometry = new MultiPolygon(polygons, GF); if (footprintCoordinates == FootprintCoordinates.MODEL_SPACE) { this.footprint = JTS.transform(innerGeometry, transform); } else { this.footprint = innerGeometry; innerGeometry.setSRID(NO_SRID); } // Compute the ROIShape if (!innerGeometry.isEmpty()) { LiteShape2 shape = new LiteShape2(innerGeometry, TRANSLATED_TX, null, false); roiShape = (ROIShape) new ROIShape(shape); } }
public MultiPolygon createMultiPolygon() { return new MultiPolygon(null, this); }
/** * Creates a MultiPolygon using the given Polygons; a null or empty array * will create an empty Polygon. The polygons must conform to the * assertions specified in the <A * HREF="http://www.opengis.org/techno/specs.htm">OpenGIS Simple Features * Specification for SQL</A>. * * @param polygons * Polygons, each of which may be empty but not null * @return the created MultiPolygon */ public MultiPolygon createMultiPolygon(Polygon[] polygons) { return new MultiPolygon(polygons, this); }
protected MultiPolygon copyInternal() { Polygon[] polygons = new Polygon[this.geometries.length]; for (int i = 0; i < polygons.length; i++) { polygons[i] = (Polygon) this.geometries[i].copy(); } return new MultiPolygon(polygons, factory); }
private Geometry onlyPolygon(Geometry result) { if ((result instanceof Polygon) || (result instanceof MultiPolygon)) { return result; } List polys = org.locationtech.jts.geom.util.PolygonExtracter.getPolygons(result); if (polys.size() == 0) { return null; } if (polys.size() == 1) { return (Polygon) polys.get(0); } // this could, theoretically, produce invalid MULTIPOLYGONS since polygons cannot share // edges. Taking // 2 polygons and putting them in a multipolygon is not always valid. However, many // systems will not correctly // deal with a GeometryCollection with multiple polygons in them. // The best strategy is to just create a (potentially) invalid multipolygon. return new MultiPolygon( (Polygon[]) polys.toArray(new Polygon[polys.size()]), result.getFactory()); }
private MultiPolygon castToMultiPolygon(Geometry geometry) { if (geometry instanceof MultiPolygon) { return (MultiPolygon) geometry; } if (geometry instanceof Polygon) { return new MultiPolygon(new Polygon[] {(Polygon) geometry}, new GeometryFactory()); } throw new GeoServerRuntimException( String.format( "Invalid geometry of type '%s' expect a Polygon or MultiPolygon.", geometry.getClass().getSimpleName())); }
@Override public MultiPolygon unmarshal(Object o) throws Exception { try { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); doc.appendChild(doc.importNode(((Element) o).getFirstChild(), true)); DOMParser parser = new DOMParser(new GMLConfiguration(), doc); Geometry geom = (Geometry) parser.parse(); if (geom instanceof Polygon) { return new MultiPolygon(new Polygon[] {(Polygon) geom}, geom.getFactory()); } else if (geom instanceof GeometryCollection) { Polygon[] pols = new Polygon[((GeometryCollection) geom).getNumGeometries()]; for (int i = 0; i < pols.length; i++) { pols[i] = (Polygon) ((GeometryCollection) geom).getGeometryN(i); } return new MultiPolygon(pols, geom.getFactory()); } return (MultiPolygon) geom; } catch (Exception e) { throw new Exception("Cannot parse specified XML as GML Polygon", e); } } }
new MultiPolygon(new Polygon[] {(Polygon) g1, (Polygon) g2}, g1.getFactory());
@Override public MultiPolygon unmarshal(Object o) throws Exception { try { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); doc.appendChild(doc.importNode(((Element) o).getFirstChild(), true)); DOMParser parser = new DOMParser(new GMLConfiguration(), doc); Geometry geom = (Geometry) parser.parse(); if (geom instanceof Polygon) { return new MultiPolygon(new Polygon[] {(Polygon) geom}, geom.getFactory()); } else if (geom instanceof GeometryCollection) { Polygon[] pols = new Polygon[((GeometryCollection) geom).getNumGeometries()]; for (int i = 0; i < pols.length; i++) { pols[i] = (Polygon) ((GeometryCollection) geom).getGeometryN(i); } return new MultiPolygon(pols, geom.getFactory()); } return (MultiPolygon) geom; } catch (Exception e) { throw new Exception("Cannot parse specified XML as GML Polygon", e); } } }
MultiPolygon polygon = new MultiPolygon(geomArray, new GeometryFactory());
} else if (geometry instanceof Polygon) { GeometryFactory factory = new GeometryFactory(); the_geom = new MultiPolygon( new Polygon[]{(Polygon) geometry}, factory);
} else if (geometry instanceof Polygon) { GeometryFactory factory = new GeometryFactory(); the_geom = new MultiPolygon( new Polygon[]{(Polygon) geometry}, factory);
} else if (geometry instanceof Polygon) { GeometryFactory factory = new GeometryFactory(); the_geom = new MultiPolygon(new Polygon[]{(Polygon) geometry}, factory);