public Object getProperty(Object object, QName name) throws Exception { Polygon p = (Polygon) object; if ("outerBoundaryIs".equals(name.getLocalPart())) { return p.getExteriorRing(); } else if ("innerBoundaryIs".equals(name.getLocalPart())) { if (p.getNumInteriorRing() > 0) { LinearRing[] interior = new LinearRing[p.getNumInteriorRing()]; for (int i = 0; i < interior.length; i++) { interior[i] = (LinearRing) p.getInteriorRingN(i); } return interior; } } return null; } }
/** * @param polygon * @throws TransformException */ public Polygon transformPolygon(Polygon polygon, GeometryFactory gf) throws TransformException { LinearRing exterior = (LinearRing) transformLineString(polygon.getExteriorRing(), gf); LinearRing[] interiors = new LinearRing[polygon.getNumInteriorRing()]; for (int i = 0; i < interiors.length; i++) { interiors[i] = (LinearRing) transformLineString(polygon.getInteriorRingN(i), gf); } Polygon transformed = gf.createPolygon(exterior, interiors); transformed.setUserData(polygon.getUserData()); return transformed; } }
public Envelope getEnvelopeInternal() { return polygon.getEnvelopeInternal(); }
/** * Lossy conversion to a GraphHopper Polygon. */ public static Polygon create(org.locationtech.jts.geom.Polygon polygon) { double[] lats = new double[polygon.getNumPoints()]; double[] lons = new double[polygon.getNumPoints()]; for (int i = 0; i < polygon.getNumPoints(); i++) { lats[i] = polygon.getCoordinates()[i].y; lons[i] = polygon.getCoordinates()[i].x; } return new Polygon(lats, lons); }
shell.setUserData(new ArrayList<LinearRing>()); if (shell.contains(hole)) { ((List<LinearRing>) shell.getUserData()).add(hole); break outer; List<LinearRing> shellHoles = ((List<LinearRing>) shell.getUserData()); punched.add(geometryFactory.createPolygon((LinearRing) (shell.getExteriorRing()), shellHoles.toArray(new LinearRing[shellHoles.size()])));
for (int j = 0; j < multiPolygon.getNumGeometries(); j++) { Polygon polygon = (Polygon) multiPolygon.getGeometryN(j); if (polygon.getNumPoints() > maxPoints) { maxPoints = polygon.getNumPoints(); maxPolygon = polygon; throw new IllegalStateException("no maximum polygon was found?"); } else { polygonShells.add(maxPolygon.getExteriorRing().getCoordinates());
/** * Create a nice Polygon from the given Polygon. Will ensure that shells are clockwise and holes * are counter-clockwise. Capiche? * * @param p The Polygon to make "nice". * @return The "nice" Polygon. */ public static final Polygon makeGoodShapePolygon(Polygon p) { GeometryFactory factory = p.getFactory(); LinearRing outer; LinearRing[] holes = new LinearRing[p.getNumInteriorRing()]; Coordinate[] coords; coords = p.getExteriorRing().getCoordinates(); if (CGAlgorithms.isCCW(coords)) { outer = reverseRing((LinearRing) p.getExteriorRing()); } else { outer = (LinearRing) p.getExteriorRing(); } for (int t = 0, tt = p.getNumInteriorRing(); t < tt; t++) { coords = p.getInteriorRingN(t).getCoordinates(); if (!(CGAlgorithms.isCCW(coords))) { holes[t] = reverseRing((LinearRing) p.getInteriorRingN(t)); } else { holes[t] = (LinearRing) p.getInteriorRingN(t); } } return factory.createPolygon(outer, holes); }
for (int i = 0; i < numGeometries; i++) { Polygon polygon = (Polygon) geometry.getGeometryN(i); if (polygon.getNumPoints() > 0) { numParts += polygon.getNumInteriorRing() + 1; shellPart[currentPart] = true; currentPart++; currentPoint += polygon.getExteriorRing().getNumPoints(); int holesCount = polygon.getNumInteriorRing(); for (int holeIndex = 0; holeIndex < holesCount; holeIndex++) { partIndexes[currentPart] = currentPoint; shellPart[currentPart] = false; currentPart++; currentPoint += polygon.getInteriorRingN(holeIndex).getNumPoints();
public void testPolygon3D() throws Exception { GML3MockData.polygon3D(document, document, true); Polygon polygon = (Polygon) parse(); assertNotNull(polygon); LineString exterior = polygon.getExteriorRing(); assertTrue(new Coordinate(1d, 2d, 10d).equals3D(exterior.getCoordinateN(0))); LineString interior = polygon.getInteriorRingN(0); assertTrue(new Coordinate(1d, 2d, 10d).equals3D(interior.getCoordinateN(0))); }
private static Geometry smoothLineString( GeometryFactory factory, GeometrySmoother smoother, Geometry geom, double fit) { if (geom instanceof LinearRing) { // Treat as a Polygon Polygon poly = factory.createPolygon((LinearRing) geom, null); Polygon smoothed = smoother.smooth(poly, fit); return smoothed.getExteriorRing(); } else { return smoother.smooth((LineString) geom, fit); } }
polygon.apply( new CoordinateSequenceFilter() { for (int i = 0; i < result.size(); i++) { Polygon item = result.get(i); if (item.getNumInteriorRing() > 0) { GeometryFactory factory = item.getFactory(); Polygon noHoles = factory.createPolygon((LinearRing) item.getExteriorRing(), null); result.set(i, noHoles);
if (polygon.getExteriorRing() != null) { buffer.append("MDSYS.SDO_GEOMETRY("); buffer.append(SDO.D(polygon)); buffer.append("MDSYS.SDO_ORDINATE_ARRAY("); CoordinateSequenceFactory fact = polygon.getFactory().getCoordinateSequenceFactory(); CoordinateSequence exterior = polygon.getExteriorRing().getCoordinateSequence(); CoordinateSequence coordSeq = SDO.counterClockWise(fact, exterior); if (polygon.getNumInteriorRing() > 0) { LOGGER.warning( "Polygon contains Interior Rings. "
public static Geometry interiorRingN(Geometry arg0, Integer arg1) { if (!(arg0 instanceof Polygon) || arg1 == null) return null; Polygon _this = (Polygon) arg0; if (arg1 < 0 || arg1 >= _this.getNumInteriorRing()) return null; return _this.getInteriorRingN(arg1); }
public static int numInteriorRing(Geometry arg0) { if (!(arg0 instanceof Polygon)) return 0; Polygon _this = (Polygon) arg0; return _this.getNumInteriorRing(); }
/** * Finds a centroid for a polygon catching any exceptions resulting from generalization or other * polygon irregularities. * * @param geom The polygon. * @return The polygon centroid, or null if it can't be found. */ public static Point getPolygonCentroid(Polygon geom) { Point centroid; try { centroid = geom.getCentroid(); } catch (Exception e) { // generalized polygons causes problems - this // tries to hide them. try { centroid = geom.getExteriorRing().getCentroid(); } catch (Exception ee) { try { centroid = geom.getFactory().createPoint(geom.getCoordinate()); } catch (Exception eee) { return null; // we're hooped } } } return centroid; }
/** * Create a new polygon without hole. * * @param polygon * @return */ public static Polygon removeHolesPolygon(Polygon polygon) { return new Polygon((LinearRing) polygon.getExteriorRing(), null, polygon.getFactory()); } }
public LineString getInteriorRingN(int n) { return polygon.getInteriorRingN(n); }
public void setUserData(Object userData) { polygon.setUserData(userData); }
/** * Returns the completed OGC Polygon. * * @param geometryFactory Geometry factory to be used in Polygon creation. * @return Completed OGC Polygon. */ public Geometry create(GeometryFactory geometryFactory) { for (int i = 0; i < innerBoundaries.size(); i++) { LinearRing hole = (LinearRing) innerBoundaries.get(i); if (hole.crosses(outerBoundary)) { LOGGER.warning("Topology Error building polygon"); return null; } } LinearRing[] rings = (LinearRing[]) innerBoundaries.toArray(new LinearRing[innerBoundaries.size()]); Polygon polygon = geometryFactory.createPolygon(outerBoundary, rings); polygon.setUserData(getSRS()); polygon.setSRID(getSRID()); return polygon; } }
poly.geometryChanged(); // djb -- jessie should do this during if (displayGeomEnv.contains(poly.getEnvelopeInternal())) { return poly.getFactory().createMultiPolygon(polys); Polygon[] polys = new Polygon[1]; polys[0] = (Polygon) clip; return poly.getFactory().createMultiPolygon(polys); return poly.getFactory().createMultiPolygon(polys.toArray(new Polygon[1]));