Java Code Examples for com.vividsolutions.jts.geom.GeometryCollection#getNumGeometries()
The following examples show how to use
com.vividsolutions.jts.geom.GeometryCollection#getNumGeometries() .
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: WKTWriter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Converts a <code>GeometryCollection</code> to <GeometryCollectionText> * format, then appends it to the writer. * *@param geometryCollection the <code>GeometryCollection</code> to process *@param writer the output writer to append to */ private void appendGeometryCollectionText(GeometryCollection geometryCollection, int level, Writer writer) throws IOException { if (geometryCollection.isEmpty()) { writer.write("EMPTY"); } else { int level2 = level; writer.write("("); for (int i = 0; i < geometryCollection.getNumGeometries(); i++) { if (i > 0) { writer.write(", "); level2 = level + 1; } appendGeometryTaggedText(geometryCollection.getGeometryN(i), level2, writer); } writer.write(")"); } }
Example 2
Source File: ShapefileHeader.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
public ShapefileHeader(GeometryCollection geometries,int dims) throws Exception { ShapeHandler handle; if (geometries.getNumGeometries() == 0) { handle = new PointHandler(); //default } else { handle = Shapefile.getShapeHandler(geometries.getGeometryN(0),dims); } int numShapes = geometries.getNumGeometries(); shapeType = handle.getShapeType(); version = Shapefile.VERSION; fileCode = Shapefile.SHAPEFILE_ID; bounds = geometries.getEnvelopeInternal(); fileLength = 0; for(int i=0;i<numShapes;i++){ fileLength+=handle.getLength(geometries.getGeometryN(i)); fileLength+=4;//for each header } fileLength+=50;//space used by this, the main header indexLength = 50+(4*numShapes); }
Example 3
Source File: GeometryPainter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
public static void paint(Graphics2D g, Viewport viewport, Geometry geometry, Style style) throws Exception { if (geometry == null) return; // cull non-visible geometries if (! viewport.intersectsInModel(geometry.getEnvelopeInternal())) return; if (geometry instanceof GeometryCollection) { GeometryCollection gc = (GeometryCollection) geometry; /** * Render each element separately. * Otherwise it is not possible to render both filled and non-filled * (1D) elements correctly */ for (int i = 0; i < gc.getNumGeometries(); i++) { paint(g, viewport, gc.getGeometryN(i), style); } return; } style.paint(geometry, viewport, g); }
Example 4
Source File: LayerRenderer.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
private void renderGeometryCollection(Graphics2D g, Viewport viewport, GeometryCollection gc, Style style ) throws Exception { /** * Render each element separately. * Otherwise it is not possible to render both filled and non-filled * (1D) elements correctly. * This also allows cancellation. */ for (int i = 0; i < gc.getNumGeometries(); i++) { render(g, viewport, gc.getGeometryN(i), style); if (isCancelled) return; } }
Example 5
Source File: JTSHelper.java From xyz-hub with Apache License 2.0 | 6 votes |
public static com.here.xyz.models.geojson.implementation.GeometryCollection fromGeometryCollection( GeometryCollection jtsGeometryCollection) { if (jtsGeometryCollection == null) { return null; } com.here.xyz.models.geojson.implementation.GeometryCollection geometryCollection = new com.here.xyz.models.geojson.implementation.GeometryCollection(); int len = jtsGeometryCollection.getNumGeometries(); List<com.here.xyz.models.geojson.implementation.GeometryItem> geometries = new ArrayList<>(); for (int i = 0; i < len; i++) { geometries.add(fromGeometry(jtsGeometryCollection.getGeometryN(i))); } return geometryCollection.withGeometries(geometries); }
Example 6
Source File: KMLWriter.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private void writeGeometryCollection(GeometryCollection gc, String attributes, int level, StringBuffer buf) { startLine("<MultiGeometry>\n", level, buf); for (int t = 0; t < gc.getNumGeometries(); t++) { writeGeometry(gc.getGeometryN(t), level + 1, buf); } startLine("</MultiGeometry>\n", level, buf); }
Example 7
Source File: GeometryCollectionWriter.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Writes a <code>GeometryCollection</code> object. * * @param o The <code>LineString</code> to be encoded. */ public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException { GeometryCollection coll = (GeometryCollection) o; document.writeElement("vml:shape", asChild); document.writeAttribute("fill-rule", "evenodd"); document.writeAttributeStart("path"); for (int i = 0; i < coll.getNumGeometries(); i++) { } document.writeAttributeEnd(); }
Example 8
Source File: SameStructureTester.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private static boolean isSameStructureCollection(GeometryCollection g1, GeometryCollection g2) { if (g1.getNumGeometries() != g2.getNumGeometries()) return false; for (int i = 0; i < g1.getNumGeometries(); i++) { if (! isSameStructure(g1.getGeometryN(i), g2.getGeometryN(i))) return false; } return true; }
Example 9
Source File: WKBWriter.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private void writeGeometryCollection(int geometryType, GeometryCollection gc, OutStream os) throws IOException { writeByteOrder(os); writeGeometryType(geometryType, gc, os); writeInt(gc.getNumGeometries(), os); for (int i = 0; i < gc.getNumGeometries(); i++) { write(gc.getGeometryN(i), os); } }
Example 10
Source File: GeometryCollectionWriter.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Writes a <code>GeometryCollection</code> object. * * @param o The <code>LineString</code> to be encoded. */ public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException { GeometryCollection coll = (GeometryCollection) o; document.writeElement("path", asChild); document.writeAttribute("fill-rule", "evenodd"); document.writeAttributeStart("d"); for (int i = 0; i < coll.getNumGeometries(); i++) { document.writeObject(coll.getGeometryN(i), true); // TODO delegate to appropriate writers, is this correct? } document.writeAttributeEnd(); }
Example 11
Source File: Envelope3D.java From gama with GNU General Public License v3.0 | 5 votes |
public static Envelope3D of(final GeometryCollection g) { final int i = g.getNumGeometries(); if (i == 0) { return EMPTY; } final Envelope3D result = of(g.getGeometryN(0)); for (int j = 1; j < i; j++) { result.expandToInclude(of(g.getGeometryN(j))); } return result; }
Example 12
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 5 votes |
public static void applyToInnerGeometries(final GeometryCollection g, final GeometryFilter f) { final int geoms = g.getNumGeometries(); if (geoms == 0) { return; } for (int i = 0; i < geoms; i++) { final Geometry sub = g.getGeometryN(i); sub.apply(f); } }
Example 13
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 5 votes |
private static IList<IShape> filterGeoms(final GeometryCollection geom, final Geometry clip, final double sizeTol, final boolean approxClipping) { if (geom == null) { return null; } final double elevation = getContourCoordinates(clip).averageZ(); final boolean setZ = elevation != 0.0; final IList<IShape> result = GamaListFactory.create(Types.GEOMETRY); final Geometry bufferClip = sizeTol != 0.0 ? clip.buffer(sizeTol, 5, 0) : clip; final PreparedGeometry buffered = PREPARED_GEOMETRY_FACTORY.create(bufferClip); final Envelope3D env = Envelope3D.of(buffered.getGeometry()); try { for (int i = 0; i < geom.getNumGeometries(); i++) { final Geometry gg = geom.getGeometryN(i); if (!clip.covers(gg.getCentroid())) continue; final Coordinate[] coord = gg.getCoordinates(); boolean cond = env.covers(gg.getCentroid().getCoordinate()); cond = cond && (approxClipping ? buffered.covers(gg.getCentroid()) && buffered.covers(GEOMETRY_FACTORY.createPoint(coord[0])) && buffered.covers(GEOMETRY_FACTORY.createPoint(coord[1])) && buffered.covers(GEOMETRY_FACTORY.createPoint(coord[2])) : bufferClip.covers(gg)); if (cond) { if (setZ) { final ICoordinates cc = getContourCoordinates(gg); cc.setAllZ(elevation); gg.geometryChanged(); } result.add(new GamaShape(gg)); } } } finally { env.dispose(); } /* * applyToInnerGeometries(geom, (gg) -> { final ICoordinates cc = getContourCoordinates(gg); if * (cc.isCoveredBy(env) && buffered.covers(gg)) { * * } }); */ return result; }
Example 14
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 5 votes |
public static IList<IShape> triangulation(final IScope scope, final IList<IShape> lines) { final IList<IShape> geoms = GamaListFactory.create(Types.GEOMETRY); final ConformingDelaunayTriangulationBuilder dtb = new ConformingDelaunayTriangulationBuilder(); final Geometry points = GamaGeometryType.geometriesToGeometry(scope, lines).getInnerGeometry(); dtb.setSites(points); dtb.setConstraints(points); final GeometryCollection tri = (GeometryCollection) dtb.getTriangles(GEOMETRY_FACTORY); final int nb = tri.getNumGeometries(); for (int i = 0; i < nb; i++) { final Geometry gg = tri.getGeometryN(i); geoms.add(new GamaShape(gg)); } return geoms; }
Example 15
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 5 votes |
public static IList<IShape> voronoi(final IScope scope, final IList<GamaPoint> points, final IShape clip) { final IList<IShape> geoms = GamaListFactory.create(Types.GEOMETRY); final VoronoiDiagramBuilder dtb = new VoronoiDiagramBuilder(); dtb.setClipEnvelope(clip.getEnvelope()); dtb.setSites(points); final GeometryCollection g = (GeometryCollection) dtb.getDiagram(GEOMETRY_FACTORY); final int nb = g.getNumGeometries(); for (int i = 0; i < nb; i++) { final Geometry gg = g.getGeometryN(i); geoms.add(new GamaShape(gg)); } return geoms; }
Example 16
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 5 votes |
public static IList<IShape> voronoi(final IScope scope, final IList<GamaPoint> points) { final IList<IShape> geoms = GamaListFactory.create(Types.GEOMETRY); final VoronoiDiagramBuilder dtb = new VoronoiDiagramBuilder(); dtb.setClipEnvelope(scope.getSimulation().getEnvelope()); dtb.setSites(points); final GeometryCollection g = (GeometryCollection) dtb.getDiagram(GEOMETRY_FACTORY); final int nb = g.getNumGeometries(); for (int i = 0; i < nb; i++) { final Geometry gg = g.getGeometryN(i); geoms.add(new GamaShape(gg.intersection(scope.getSimulation().getInnerGeometry()))); } return geoms; }
Example 17
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 18
Source File: GeometryPainter.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
private static void paint(Geometry geometry, ShapeWriter converter, Graphics2D g, Color lineColor, Color fillColor, Stroke stroke) { if (geometry == null) return; if (geometry instanceof GeometryCollection) { GeometryCollection gc = (GeometryCollection) geometry; /** * Render each element separately. * Otherwise it is not possible to render both filled and non-filled * (1D) elements correctly */ for (int i = 0; i < gc.getNumGeometries(); i++) { paint(gc.getGeometryN(i), converter, g, lineColor, fillColor, stroke); } return; } Shape shape = converter.toShape(geometry); // handle points in a special way for appearance and speed if (geometry instanceof Point) { g.setStroke(POINT_STROKE); g.setColor(lineColor); g.draw(shape); return; } if (stroke == null) g.setStroke(GEOMETRY_STROKE); else g.setStroke(stroke); // Test for a polygonal shape and fill it if required if (geometry instanceof Polygon && fillColor != null) { // if (!(shape instanceof GeneralPath) && fillColor != null) { g.setPaint(fillColor); g.fill(shape); } if (lineColor != null) { g.setColor(lineColor); try { g.draw(shape); // draw polygon boundaries twice, to discriminate them // MD - this isn't very obvious. Perhaps a dashed line instead? /* if (geometry instanceof Polygon) { Shape polyShell = converter.toShape( ((Polygon)geometry).getExteriorRing()); g.setStroke(new BasicStroke(2)); g.draw(polyShell); } */ } catch (Throwable ex) { System.out.println(ex); // eat it! } } }
Example 19
Source File: TopologicalOverlay.java From geowe-core with GNU General Public License v3.0 | 4 votes |
public List<String> getOverlay(final Geometry layer1, final Geometry layer2, final int op) { final List<String> resultLayer = new ArrayList<String>(); Geometry geomContorno = null; switch (op) { case OverlayOp.INTERSECTION: geomContorno = EnhancedPrecisionOp.intersection( layer1.buffer(TOLERANCIA), layer2.buffer(TOLERANCIA)); break; case OverlayOp.DIFFERENCE: geomContorno = EnhancedPrecisionOp.difference( layer1.buffer(TOLERANCIA), layer2.buffer(TOLERANCIA)); break; case OverlayOp.SYMDIFFERENCE: geomContorno = EnhancedPrecisionOp.symDifference( layer1.buffer(TOLERANCIA), layer2.buffer(TOLERANCIA)); break; default: break; } if (geomContorno != null) { if (geomContorno instanceof Polygon) { resultLayer.add(geomContorno.toText()); } else if (geomContorno instanceof MultiPolygon) { final MultiPolygon multiPolygon = (MultiPolygon) geomContorno; for (int i = 0; i < multiPolygon.getNumGeometries(); i++) { final Polygon pol = (Polygon) multiPolygon.getGeometryN(i); resultLayer.add(pol.toText()); } } else if (geomContorno instanceof GeometryCollection) { final GeometryCollection gc = (GeometryCollection) geomContorno; for (int i = 0; i < gc.getNumGeometries(); i++) { final Geometry geom = gc.getGeometryN(i); resultLayer.add(geom.toText()); } } } return resultLayer; }
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); } }