Java Code Examples for com.vividsolutions.jts.geom.Polygon#getNumInteriorRing()
The following examples show how to use
com.vividsolutions.jts.geom.Polygon#getNumInteriorRing() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GamaGisFile.java From gama with GNU General Public License v3.0 | 8 votes |
protected Geometry multiPolygonManagement(final Geometry geom) { if (geom instanceof MultiPolygon) { final Polygon gs[] = new Polygon[geom.getNumGeometries()]; for (int i = 0; i < geom.getNumGeometries(); i++) { final Polygon p = (Polygon) geom.getGeometryN(i); final ICoordinates coords = GeometryUtils.getContourCoordinates(p); final LinearRing lr = GEOMETRY_FACTORY.createLinearRing(coords.toCoordinateArray()); try (final Collector.AsList<LinearRing> holes = Collector.getList()) { for (int j = 0; j < p.getNumInteriorRing(); j++) { final LinearRing h = (LinearRing) p.getInteriorRingN(j); if (!hasNullElements(h.getCoordinates())) { holes.add(h); } } LinearRing[] stockArr = new LinearRing[holes.size()]; stockArr = holes.items().toArray(stockArr); gs[i] = GEOMETRY_FACTORY.createPolygon(lr, stockArr); } } return GEOMETRY_FACTORY.createMultiPolygon(gs); } return geom; }
Example 2
Source File: OraReader.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Create MultiPolygon as encoded by elemInfo. * * @param oraGeom SDO_GEOMETRY attributes being read * @param coords the coordinates of the entire geometry * @return MultiPolygon */ private MultiPolygon readMultiPolygon(OraGeom oraGeom) { int nElem = oraGeom.numElements(); List geoms = new ArrayList(); for (int i = 0; i < nElem; i++) { int etype = oraGeom.eType(i); if ((etype == OraGeom.ETYPE.POLYGON) || (etype == OraGeom.ETYPE.POLYGON_EXTERIOR)) { Polygon poly = readPolygon(oraGeom, i); i += poly.getNumInteriorRing(); // skip interior rings geoms.add(poly); } else { // not a Polygon - stop reading break; } } MultiPolygon polys = geometryFactory.createMultiPolygon(GeometryFactory.toPolygonArray(geoms)); return polys; }
Example 3
Source File: MultiPolygonWriter.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
/** * Writes the body for a <code>MultiPolygon</code> object. MultiPolygons are * encoded into SVG path elements. This function writes the different * polygons in one d-attribute of an SVG path element, separated by an 'M' * character. (in other words, it calls the super.writeBody for each * polygon). * * @param o The <code>MultiPolygon</code> to be encoded. */ public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException { document.writeElement("path", asChild); document.writeAttribute("fill-rule", "evenodd"); document.writeAttributeStart("d"); MultiPolygon mpoly = (MultiPolygon) o; for (int i = 0; i < mpoly.getNumGeometries(); i++) { Polygon poly = (Polygon) mpoly.getGeometryN(i); LineString shell = poly.getExteriorRing(); int nHoles = poly.getNumInteriorRing(); document.writeClosedPathContent(shell.getCoordinates()); for (int j = 0; j < nHoles; j++) { document.writeClosedPathContent(poly.getInteriorRingN(j).getCoordinates()); } } document.writeAttributeEnd(); }
Example 4
Source File: MultiPolygonWriter.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
/** * Writes the body for a <code>MultiPolygon</code> object. MultiPolygons are * encoded into SVG path elements. This function writes the different * polygons in one d-attribute of an SVG path element, separated by an 'M' * character. (in other words, it calls the super.writeBody for each * polygon). * * @param o The <code>MultiPolygon</code> to be encoded. */ public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException { document.writeElement("vml:shape", asChild); document.writeAttribute("fill-rule", "evenodd"); document.writeAttributeStart("path"); MultiPolygon mpoly = (MultiPolygon) o; for (int i = 0; i < mpoly.getNumGeometries(); i++) { Polygon poly = (Polygon) mpoly.getGeometryN(i); LineString shell = poly.getExteriorRing(); int nHoles = poly.getNumInteriorRing(); document.writeClosedPathContent(shell.getCoordinates()); for (int j = 0; j < nHoles; j++) { document.writeClosedPathContent(poly.getInteriorRingN(j).getCoordinates()); } } document.writeAttributeEnd(); }
Example 5
Source File: WKTWriter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Converts a <code>Polygon</code> to <Polygon Text> format, then * appends it to the writer. * *@param polygon the <code>Polygon</code> to process *@param writer the output writer to append to */ private void appendPolygonText(Polygon polygon, int level, boolean indentFirst, Writer writer) throws IOException { if (polygon.isEmpty()) { writer.write("EMPTY"); } else { if (indentFirst) indent(level, writer); writer.write("("); appendLineStringText(polygon.getExteriorRing(), level, false, writer); for (int i = 0; i < polygon.getNumInteriorRing(); i++) { writer.write(", "); appendLineStringText(polygon.getInteriorRingN(i), level + 1, true, writer); } writer.write(")"); } }
Example 6
Source File: KMLWriter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
private void writePolygon(Polygon p, String attributes, int level, StringBuffer buf) { startLine(geometryTag("Polygon", attributes) + "\n", level, buf); writeModifiers(level, buf); startLine(" <outerBoundaryIs>\n", level, buf); writeLinearRing((LinearRing) p.getExteriorRing(), null, false, level + 1, buf); startLine(" </outerBoundaryIs>\n", level, buf); for (int t = 0; t < p.getNumInteriorRing(); t++) { startLine(" <innerBoundaryIs>\n", level, buf); writeLinearRing((LinearRing) p.getInteriorRingN(t), null, false, level + 1, buf); startLine(" </innerBoundaryIs>\n", level, buf); } startLine("</Polygon>\n", level, buf); }
Example 7
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 6 votes |
public static Geometry cleanGeometry(final Geometry g) { //follow the proposition of https://locationtech.github.io/jts/jts-faq.html#G1 if (g == null || g.isEmpty()) return g; Geometry g2 = g.buffer(0.0, BufferParameters.DEFAULT_QUADRANT_SEGMENTS, BufferParameters.CAP_FLAT); if (g2.isEmpty()) { if (g instanceof Polygon) { Polygon p = (Polygon) g; Geometry g3 = GeometryUtils.GEOMETRY_FACTORY.createPolygon(p.getExteriorRing().getCoordinates()); for (int i = 0; i < p.getNumInteriorRing(); i++) { Geometry g4 = GeometryUtils.GEOMETRY_FACTORY.createPolygon(p.getInteriorRingN(i).getCoordinates()); g3 = g3.difference(g4); } return g3; }else { return GeometryUtils.GEOMETRY_FACTORY.createGeometry(g); } } return g2; }
Example 8
Source File: JTSHelper.java From xyz-hub with Apache License 2.0 | 6 votes |
/** * Create GeoJSON Polygon coordinates. */ public static PolygonCoordinates createPolygonCoordinates(Polygon geom) { if (geom == null) { return null; } LinearRing shell = (LinearRing) geom.getExteriorRing(); int lenInterior = geom.getNumInteriorRing(); PolygonCoordinates polygonCoordinates = new PolygonCoordinates(lenInterior + 1); polygonCoordinates.add(createLinearRingCoordinates(shell)); for (int i = 0; i < lenInterior; i++) { polygonCoordinates.add(createLinearRingCoordinates((LinearRing) geom.getInteriorRingN(i))); } return polygonCoordinates; }
Example 9
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 5 votes |
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); } }
Example 10
Source File: GamaShape.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public IList<GamaShape> getHoles() { final IList<GamaShape> holes = GamaListFactory.create(Types.GEOMETRY); if (getInnerGeometry() instanceof Polygon) { final Polygon p = (Polygon) getInnerGeometry(); final int n = p.getNumInteriorRing(); for (int i = 0; i < n; i++) { holes.add(new GamaShape(GEOMETRY_FACTORY.createPolygon(p.getInteriorRingN(i).getCoordinates()))); } } return holes; }
Example 11
Source File: GamaProxyGeometry.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Method getHoles() * * @see msi.gama.metamodel.shape.IShape#getHoles() */ @Override public IList<GamaShape> getHoles() { final IList<GamaShape> holes = GamaListFactory.create(Types.GEOMETRY); final Geometry g = getInnerGeometry(); if (g instanceof Polygon) { final Polygon p = (Polygon) g; final int n = p.getNumInteriorRing(); for (int i = 0; i < n; i++) { holes.add(new GamaShape( GeometryUtils.GEOMETRY_FACTORY.createPolygon(p.getInteriorRingN(i).getCoordinates()))); } } return holes; }
Example 12
Source File: GeoTools.java From xyz-hub with Apache License 2.0 | 5 votes |
/** * Add all line strings from the polygon given to the polygonizer given * * @param polygon polygon from which to extract line strings * @param polygonizer polygonizer */ static void addPolygon(Polygon polygon, Polygonizer polygonizer) { addLineString(polygon.getExteriorRing(), polygonizer); for (int n = polygon.getNumInteriorRing(); n-- > 0; ) { addLineString(polygon.getInteriorRingN(n), polygonizer); } }
Example 13
Source File: Distance3DOp.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Compute distance between a polygon and the rings of another. * * @param poly * @param ringPoly * @param geomIndex */ private void computeMinDistancePolygonRings(PlanarPolygon3D poly, Polygon ringPoly, boolean flip) { // compute shell ring computeMinDistancePolygonLine(poly, ringPoly.getExteriorRing(), flip); if (isDone) return; // compute hole rings int nHole = ringPoly.getNumInteriorRing(); for (int i = 0; i < nHole; i++) { computeMinDistancePolygonLine(poly, ringPoly.getInteriorRingN(i), flip); if (isDone) return; } }
Example 14
Source File: WKBWriter.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private void writePolygon(Polygon poly, OutStream os) throws IOException { writeByteOrder(os); writeGeometryType(WKBConstants.wkbPolygon, poly, os); writeInt(poly.getNumInteriorRing() + 1, os); writeCoordinateSequence(poly.getExteriorRing().getCoordinateSequence(), true, os); for (int i = 0; i < poly.getNumInteriorRing(); i++) { writeCoordinateSequence(poly.getInteriorRingN(i).getCoordinateSequence(), true, os); } }
Example 15
Source File: SameStructureTester.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private static boolean isSameStructurePolygon(Polygon g1, Polygon g2) { if (g1.getNumInteriorRing() != g2.getNumInteriorRing()) return false; // could check for both empty or nonempty here return true; }
Example 16
Source File: PdfContext.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
private void drawGeometry(Geometry g, SymbolInfo symbol) { if (g instanceof MultiPolygon) { MultiPolygon mpoly = (MultiPolygon) g; for (int i = 0; i < mpoly.getNumGeometries(); i++) { drawGeometry(mpoly.getGeometryN(i), symbol); } } else if (g instanceof MultiLineString) { MultiLineString mline = (MultiLineString) g; for (int i = 0; i < mline.getNumGeometries(); i++) { drawGeometry(mline.getGeometryN(i), symbol); } } else if (g instanceof MultiPoint) { MultiPoint mpoint = (MultiPoint) g; for (int i = 0; i < mpoint.getNumGeometries(); i++) { drawGeometry(mpoint.getGeometryN(i), symbol); } } else if (g instanceof Polygon) { Polygon poly = (Polygon) g; LineString shell = poly.getExteriorRing(); int nHoles = poly.getNumInteriorRing(); drawPathContent(shell.getCoordinates()); for (int j = 0; j < nHoles; j++) { drawPathContent(poly.getInteriorRingN(j).getCoordinates()); } template.closePathEoFillStroke(); } else if (g instanceof LineString) { LineString line = (LineString) g; drawPathContent(line.getCoordinates()); template.stroke(); } else if (g instanceof Point) { Point point = (Point) g; drawPoint(point.getCoordinate(), symbol); template.fillStroke(); } }
Example 17
Source File: PolygonWriter.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Writes the object to the specified document, optionally creating a child * element. The object in this case should be a polygon. * * @param o the object (of type Polygon). * @param document the document to write to. * @param asChild create child element if true. * @throws RenderException */ public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException { document.writeElement("vml:shape", asChild); document.writeAttributeStart("path"); Polygon poly = (Polygon) o; LineString shell = poly.getExteriorRing(); int nHoles = poly.getNumInteriorRing(); document.writeClosedPathContent(shell.getCoordinates()); for (int j = 0; j < nHoles; j++) { document.writeClosedPathContent(poly.getInteriorRingN(j).getCoordinates()); } document.writeAttributeEnd(); }
Example 18
Source File: CoordinateUtil.java From geowe-core with GNU General Public License v3.0 | 5 votes |
public void addCoordinateArrays(final Geometry geometry, final boolean orientPolygons, final List<Coordinate[]> coordArrayList) { if (geometry.getDimension() <= 0) { return; } else if (geometry instanceof LineString) { final LineString l = (LineString) geometry; coordArrayList.add(l.getCoordinates()); } else if (geometry instanceof Polygon) { final Polygon poly = (Polygon) geometry; Coordinate[] shell = poly.getExteriorRing().getCoordinates(); if (orientPolygons) { shell = ensureOrientation(CGAlgorithms.CLOCKWISE, shell); } coordArrayList.add(shell); for (int numRing = 0; numRing < poly.getNumInteriorRing(); numRing++) { Coordinate[] hole = poly.getInteriorRingN(numRing).getCoordinates(); if (orientPolygons) { hole = ensureOrientation( CGAlgorithms.COUNTERCLOCKWISE, hole); } coordArrayList.add(hole); } } else if (geometry instanceof GeometryCollection) { final GeometryCollection gc = (GeometryCollection) geometry; for (int numGeom = 0; numGeom < gc.getNumGeometries(); numGeom++) { addCoordinateArrays(gc.getGeometryN(numGeom), orientPolygons, coordArrayList); } } }
Example 19
Source File: PolygonWriter.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException { document.writeElement("path", asChild); document.writeAttribute("fill-rule", "evenodd"); document.writeAttributeStart("d"); Polygon poly = (Polygon) o; LineString shell = poly.getExteriorRing(); int nHoles = poly.getNumInteriorRing(); document.writeClosedPathContent(shell.getCoordinates()); for (int j = 0; j < nHoles; j++) { document.writeClosedPathContent(poly.getInteriorRingN(j).getCoordinates()); } document.writeAttributeEnd(); }
Example 20
Source File: GeometryValidator.java From geowe-core with GNU General Public License v3.0 | 4 votes |
private void validate(final Geometry geom, final List<ValidationResult> validationErrors) { if (geom.isEmpty()) { return; } if (geom instanceof GeometryCollection) { final GeometryCollection gc = (GeometryCollection) geom; for (int numGeom = 0; numGeom < gc.getNumGeometries(); numGeom++) { validate(gc.getGeometryN(numGeom), validationErrors); } } final ValidationResult result = new ValidationResult(); result.setWkt(geom.toText()); final List<String> messages = new ArrayList<String>(); if (!geom.isValid()) { messages.add("Error en topología básica"); } if (!geom.isSimple()) { messages.add("No es una geometría simple"); } if (repeatedPointTester.hasRepeatedPoint(geom)) { messages.add("Se encuentran vértices repetidos"); } if (geom instanceof Polygon) { final Polygon polygon = (Polygon) geom; if (CGAlgorithms.isCCW(polygon.getExteriorRing().getCoordinates())) { messages.add("Error en orientación del polígono"); } else { for (int numRing = 0; numRing < polygon.getNumInteriorRing(); numRing++) { if (!CGAlgorithms.isCCW(polygon.getInteriorRingN(numRing).getCoordinates())) { messages.add("Error en orientación del polígono en anillos interiores"); break; } } } if (!validateMinPolygonArea(geom)) { messages.add("Error en validación mínima de area de un polígono"); } } if (!validateMinSegmentLength(geom)) { messages.add("Error en validación mínima de longitud de segmento. Coordenadas"); result.setErrorsPoints(errorCoordinates); } if(!messages.isEmpty()) { result.setMessages(messages); validationErrors.add(result); } }