public MultiPolygon toJTSMultiPolygon() { if (jtsMultiPolygon == null) { List<Polygon> polygons = new ArrayList<Polygon>(); for (Ring ring : outermostRings) { polygons.add(ring.toJtsPolygon()); } jtsMultiPolygon = GeometryUtils.getGeometryFactory().createMultiPolygon( polygons.toArray(new Polygon[0])); if (!jtsMultiPolygon.isValid()) { throw new AreaConstructionException(); } } return jtsMultiPolygon; }
Geometry u = geometryFactory.createMultiPolygon(allRings.toArray(new Polygon[allRings .size()])); u = u.union();
return geomFactory.createMultiPolygon(polygons.toArray(new Polygon[polygons.size()]));
jtsPolygons[i++] = (Polygon) convertGeoJsonToJtsGeometry(geoJsonPoly); return gf.createMultiPolygon(jtsPolygons);
public Object parse(Handler arg, GeometryFactory gf) throws SAXException { // one child, either a coord // or a coordinate sequence if(arg.children.size()<1) throw new SAXException("Cannot create a multi-polygon without atleast one polygon"); int srid = getSrid(arg.attrs,gf.getSRID()); Polygon[] plys = (Polygon[]) arg.children.toArray(new Polygon[arg.children.size()]); MultiPolygon mp = gf.createMultiPolygon(plys); if(mp.getSRID()!=srid) mp.setSRID(srid); return mp; } });
/** * 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); } }
/** * Creates a <code>MultiPolygon</code> using the next token in the stream. * *@param tokenizer tokenizer over a stream of text in Well-known Text * format. The next tokens must form a <MultiPolygon Text>. *@return a <code>MultiPolygon</code> specified by the next * token in the stream, or if if the coordinates used to create the * <code>Polygon</code> shells and holes do not form closed linestrings. *@throws IOException if an I/O error occurs *@throws ParseException if an unexpected token was encountered */ private MultiPolygon readMultiPolygonText() throws IOException, ParseException { String nextToken = getNextEmptyOrOpener(); if (nextToken.equals(EMPTY)) { return geometryFactory.createMultiPolygon(new Polygon[]{}); } ArrayList polygons = new ArrayList(); Polygon polygon = readPolygonText(); polygons.add(polygon); nextToken = getNextCloserOrComma(); while (nextToken.equals(COMMA)) { polygon = readPolygonText(); polygons.add(polygon); nextToken = getNextCloserOrComma(); } Polygon[] array = new Polygon[polygons.size()]; return geometryFactory.createMultiPolygon((Polygon[]) polygons.toArray(array)); }
private MultiPolygon readMultiPolygon() throws IOException, ParseException { int numGeom = dis.readInt(); Polygon[] geoms = new Polygon[numGeom]; for (int i = 0; i < numGeom; i++) { Geometry g = readGeometry(); if (! (g instanceof Polygon)) throw new ParseException(INVALID_GEOM_TYPE_MSG + "MultiPolygon"); geoms[i] = (Polygon) g; } return factory.createMultiPolygon(geoms); }
/** * Computes a {@link Geometry} containing only {@link Polygonal} components. * Extracts the {@link Polygon}s from the input * and returns them as an appropriate {@link Polygonal} geometry. * <p> * If the input is already <tt>Polygonal</tt>, it is returned unchanged. * <p> * A particular use case is to filter out non-polygonal components * returned from an overlay operation. * * @param g the geometry to filter * @return a Polygonal geometry */ private static Geometry restrictToPolygons(Geometry g) { if (g instanceof Polygonal) { return g; } List polygons = PolygonExtracter.getPolygons(g); if (polygons.size() == 1) return (Polygon) polygons.get(0); return g.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons)); } }
return factory.createMultiPolygon((Polygon[]) geometries.toArray( new Polygon[] { }));
if (isCollection) { if (geom0 instanceof Polygon) { return createMultiPolygon(toPolygonArray(geomList));
/** * Creates a MultiPolygon from a set of Polygons. * * @param polys the component polygons * @return A MultiPolygon */ public MultiPolygon multiPolygon(Polygon... polys) { return geomFact.createMultiPolygon(polys); }
private Geometry toPolygon(GeometryFactory gf, final List<Polygon> polygons) { if(polygons.size() == 0) { return gf.createGeometryCollection(null); } else if(polygons.size() == 1) { return polygons.get(0); } else { return gf.createMultiPolygon((Polygon[]) polygons.toArray(new Polygon[polygons.size()])); } }
@Override public MultiPolygon createMultiPolygon(Polygon[] polygons) { if (polygons != null && polygons.length == 1) { return new SinglePolygonCollection(polygons, this); } else { return super.createMultiPolygon(polygons); } }
private MultiPolygon createMulti(LinearRing single,List holes) { return geometryFactory.createMultiPolygon( new Polygon[] { geometryFactory.createPolygon(single, (LinearRing[]) holes.toArray(new LinearRing[holes.size()])) } ); }
private MultiPolygon createMulti(LinearRing single, List holes) { return geometryFactory .createMultiPolygon(new Polygon[] { geometryFactory .createPolygon(single, (LinearRing[]) holes .toArray(new LinearRing[holes.size()])) }); }
private static GeometryCollection returnEmptyCollection(int outputDimension) { switch (outputDimension) { case 2: return new GeometryFactory().createMultiPolygon(new Polygon[0]); case 1: return new GeometryFactory().createMultiLineString(new LineString[0]); default: return new GeometryFactory().createMultiPoint(new Point[0]); } }
public MultiPolygon createMultiPolygon(Shape shape) { List<LinearRing> linearRings = createLinearRingList(shape); Polygon[] polygons = new Polygon[linearRings.size()]; for (int i = 0; i < linearRings.size(); i++) { LinearRing linearRing = linearRings.get(i); polygons[i] = geometryFactory.createPolygon(linearRing, null); } return geometryFactory.createMultiPolygon(polygons); }
public static MultiPolygon getMultiPolygonGeometry(JSONArray polygon) { Polygon polygons[] = new Polygon[polygon.length()]; for(int i = 0; i < polygon.length(); i++) { polygons[i] = getPolygonGeometry(polygon.getJSONArray(i)); } return factory.createMultiPolygon(polygons); }
@Override public MultiPolygon toObject(String s) { Geometry g = toGeometry(s); if (g == null) return null; if (g instanceof MultiPolygon) return (MultiPolygon)g; if (g instanceof Polygon) return g.getFactory().createMultiPolygon(new Polygon[]{(Polygon)g}); return null; }