int maxPoints = 0; Polygon maxPolygon = null; for (int j = 0; j < multiPolygon.getNumGeometries(); j++) { Polygon polygon = (Polygon) multiPolygon.getGeometryN(j); if (polygon.getNumPoints() > maxPoints) { maxPoints = polygon.getNumPoints();
/** * 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); } }
Envelope box = multi.getEnvelopeInternal(); buffer.putDouble(box.getMinX()); buffer.putDouble(box.getMinY()); for (int t = 0; t < multi.getNumGeometries(); t++) { Polygon p; p = (Polygon) multi.getGeometryN(t); allCoords.add(p.getExteriorRing().getCoordinateSequence()); for (int ringN = 0; ringN < p.getNumInteriorRing(); ringN++) { final int npoints = multi.getNumPoints();
else if (bFilter == null) rasterFilter = aFilter; else { Geometry intersection = aFilter.intersection(bFilter); if (intersection instanceof MultiPolygon) { rasterFilter = (MultiPolygon) intersection; if (rasterFilter != null && rasterFilter.getNumGeometries() == 0) { readFilter = Filter.EXCLUDE; } else {
/** * 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; }
/** * Converts a <code>MultiPolygon</code> to <MultiPolygon Text> format, then appends it to * the writer. * * @param multiPolygon the <code>MultiPolygon</code> to process * @param writer the output writer to append to */ private void appendMultiPolygonText(MultiPolygon multiPolygon, int level, Writer writer) throws IOException { if (multiPolygon.isEmpty()) { writer.write("EMPTY"); } else { int level2 = level; boolean doIndent = false; writer.write("("); for (int i = 0; i < multiPolygon.getNumGeometries(); i++) { if (i > 0) { writer.write(", "); level2 = level + 1; doIndent = true; } appendPolygonText((Polygon) multiPolygon.getGeometryN(i), level2, doIndent, writer); } writer.write(")"); } }
public int getLength(Object geometry) { MultiPolygon multi; if (geometry instanceof MultiPolygon) { multi = (MultiPolygon) geometry; } else { multi = geometryFactory.createMultiPolygon(new Polygon[] {(Polygon) geometry}); } int nrings = 0; for (int t = 0; t < multi.getNumGeometries(); t++) { Polygon p; p = (Polygon) multi.getGeometryN(t); nrings = nrings + 1 + p.getNumInteriorRing(); } int npoints = multi.getNumPoints(); int length; if (shapeType == ShapeType.POLYGONZ) { length = 44 + (4 * nrings) + (16 * npoints) + (8 * npoints) + 16 + (8 * npoints) + 16; } else if (shapeType == ShapeType.POLYGONM) { length = 44 + (4 * nrings) + (16 * npoints) + (8 * npoints) + 16; } else if (shapeType == ShapeType.POLYGON) { length = 44 + (4 * nrings) + (16 * npoints); } else { throw new IllegalStateException("Expected ShapeType of Polygon, got " + shapeType); } return length; }
public void testParseWithSurfaceMembers() throws Exception { GML3MockData.multiSurface(document, document, false); MultiPolygon mpoly = (MultiPolygon) parse(); assertEquals(2, mpoly.getNumGeometries()); } }
@Override public Object getProperty(Object object, QName name) throws Exception { if ("_Surface".equals(name.getLocalPart()) || "AbstractSurface".equals(name.getLocalPart())) { MultiPolygon multiPolygon = (MultiPolygon) object; // this MultiPolygon consists of a single Polygon wrapped in a MultiPolygon: return multiPolygon.getGeometryN(0); } return super.getProperty(object, name); }
if (geometry instanceof MultiPolygon) { the_geom = (MultiPolygon) geometry; the_geom.setSRID(Integer .valueOf(layerLimitsForm.getSrid()).intValue()); ruleLimits.setAllowedArea(the_geom); } else if (geometry instanceof Polygon) { GeometryFactory factory = new GeometryFactory(); the_geom = new MultiPolygon( new Polygon[]{(Polygon) geometry}, factory); the_geom.setSRID(Integer .valueOf(layerLimitsForm.getSrid()).intValue()); ruleLimits.setAllowedArea(the_geom);
polys.setSRID(SRID);
} else if (geometry instanceof Polygon) { GeometryFactory factory = new GeometryFactory(); the_geom = new MultiPolygon(new Polygon[]{(Polygon) geometry}, factory); layerDetailsInfo.setAllowedArea(the_geom.toText()); layerDetailsInfo .setSrid(String.valueOf(the_geom.getSRID())); } else { layerDetailsInfo.setAllowedArea(null);
Polygon[] polygonArray = geometryFactory.toPolygonArray(geometries); MultiPolygon multiPolygon = geometryFactory.createMultiPolygon(polygonArray); multiPolygon.setUserData(getSRS()); multiPolygon.setSRID(getSRID()); LOGGER.fine("created " + multiPolygon);
MultiPolygon polygon = new MultiPolygon(geomArray, new GeometryFactory()); return polygon.toText();
Envelope env = multiPolygon.getEnvelopeInternal(); minX = env.getMinX(); maxX = env.getMaxX();
public void testEmptyMultiPolygon() throws Exception { MultiPolygon g = geometryFactory.createMultiPolygon(null); assertEquals(2, g.getDimension()); assertEquals(new Envelope(), g.getEnvelopeInternal()); assertTrue(g.isSimple()); }
/** * 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); }
if ((pp != null) && (!(pp.isEmpty()))) { for (int t = 0; t < pp.getNumGeometries(); t++) clippedPolys.add((Polygon) pp.getGeometryN(t));