private static Polygon getSubPolygon(Polygon polygon, int startIndex, int endIndex) { Polyline boundary = new Polyline(); boundary.startPath(polygon.getPoint(startIndex)); for (int i = startIndex + 1; i < endIndex; i++) { Point current = polygon.getPoint(i); boundary.lineTo(current); } final Polygon newPolygon = new Polygon(); newPolygon.add(boundary, false); return newPolygon; }
if (polygon.getPathCount() > 1) { return false; if (polygon.getPointCount() != 4) { return false; Point point = polygon.getPoint(i); if (!corners.contains(point)) { return false;
switch (type) { case Polygon: { if (!multiType && ((Polygon) geometry).getExteriorRingCount() <= 1) { return new OGCPolygon((Polygon) geometry, null); Polygon polygon = new Polygon(); polygon.addEnvelope((Envelope) geometry, false); return new OGCPolygon(polygon, null);
private static Point computePolygonCentroid(Polygon polygon) { int pathCount = polygon.getPathCount(); if (pathCount == 1) { return getPolygonSansHolesCentroid(polygon); } double xSum = 0; double ySum = 0; double areaSum = 0; for (int i = 0; i < pathCount; i++) { int startIndex = polygon.getPathStart(i); int endIndex = polygon.getPathEnd(i); Polygon sansHoles = getSubPolygon(polygon, startIndex, endIndex); Point centroid = getPolygonSansHolesCentroid(sansHoles); double area = sansHoles.calculateArea2D(); xSum += centroid.getX() * area; ySum += centroid.getY() * area; areaSum += area; } return new Point(xSum / areaSum, ySum / areaSum); }
private static Point getPolygonSansHolesCentroid(Polygon polygon) { int pointCount = polygon.getPointCount(); double xSum = 0; double ySum = 0; double signedArea = 0; for (int i = 0; i < pointCount; i++) { Point current = polygon.getPoint(i); Point next = polygon.getPoint((i + 1) % polygon.getPointCount()); double ladder = current.getX() * next.getY() - next.getX() * current.getY(); xSum += (current.getX() + next.getX()) * ladder; ySum += (current.getY() + next.getY()) * ladder; signedArea += ladder / 2; } return new Point(xSum / (signedArea * 6), ySum / (signedArea * 6)); }
Geometry _OffsetEnvelope() { Envelope envelope = (Envelope) m_inputGeometry; if ((m_distance > 0) && (m_joins != OperatorOffset.JoinType.Miter)) { Polygon poly = new Polygon(); poly.addEnvelope(envelope, false); m_inputGeometry = poly; return _ConstructOffset(); } Envelope resEnv = new Envelope(envelope.m_envelope); resEnv.inflate(m_distance, m_distance); return resEnv; }
MultiPath input_mp = (MultiPath) (input_geom); MultiPathImpl mp_impl = (MultiPathImpl) (input_mp._getImpl()); Polygon intermediate_polygon = new Polygon(input_geom.getDescription()); for (int ipath = ipath_begin; ipath < ipath_end; ipath++) { if (mp_impl.getPathSize(ipath) < 1) point.setXY(env2D.getCenter()); addCircle_( (MultiPathImpl) intermediate_polygon._getImpl(), point); } else { Polyline result_polyline = new Polyline( input_geom.getDescription()); MultiPathImpl result_mp = (MultiPathImpl) result_polyline ._getImpl(); Polygon buffered_path = bufferConvexPath_(input_mp, ipath); intermediate_polygon.add(buffered_path, false); } else { Polygon buffered_path = bufferCleanup_( result_polyline, false); intermediate_polygon.add(buffered_path, false); input_geom.getDescription()); MultiPathImpl result_mp = (MultiPathImpl) result_polyline ._getImpl(); for (int i = 1, n = buffered_path.getPathCount(); i < n; i++)
/** * Read a polygon that has a unique part. * @param numPoints Number of the points of the polygon. * @return Polygon. */ @Deprecated // As soon as the readMultiplePolygonParts method proofs working well, this readUniquePolygonPart method can be removed and all calls be deferred to readMultiplePolygonParts. private Polygon readUniquePolygonPart(int numPoints) { /*int part = */ getByteBuffer().getInt(); Polygon poly = new Polygon(); // create a line from the points double xpnt = getByteBuffer().getDouble(); double ypnt = getByteBuffer().getDouble(); poly.startPath(xpnt, ypnt); for (int j = 0; j < numPoints - 1; j++) { xpnt = getByteBuffer().getDouble(); ypnt = getByteBuffer().getDouble(); poly.lineTo(xpnt, ypnt); } return poly; }
case Polygon: Polygon polygon = (Polygon)(esriGeom); resultInt.set(polygon.getPointCount() + polygon.getPathCount()); break; default:
private static boolean polygonEqualsEnvelope_(Polygon polygon_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); // Quick envelope rejection test for false equality. // This check will correctly handle degenerate envelope cases (i.e. // degenerate to point or line) if (!envelopeEqualsEnvelope_(env_a, env_b, tolerance, progress_tracker)) return false; Polygon polygon_b = new Polygon(); polygon_b.addEnvelope(envelope_b, false); return linearPathEqualsLinearPath_(polygon_a, polygon_b, tolerance, true); }
public OGCPolygon(Polygon src, int exteriorRing, SpatialReference sr) { polygon = new Polygon(); for (int i = exteriorRing, n = src.getPathCount(); i < n; i++) { if (i > exteriorRing && src.isExteriorRing(i)) break; polygon.addPath(src, i, true); } esriSR = sr; }
Envelope2D env_a_inf = new Envelope2D(), env_b_inf = new Envelope2D(); MultiPathImpl multi_path_impl_a = (MultiPathImpl)polygon_a._getImpl(); MultiPathImpl multi_path_impl_b = (MultiPathImpl)multipath_b._getImpl(); pt_a = polygon_a.getXY(polygon_a.getPathStart(path_a)); env_b_inf.setCoords(intersector.getBlueEnvelope()); env_b_inf.inflate(tolerance, tolerance); pa = new Polygon(); polygon_a.copyTo(pa); ((MultiPathImpl) pa._getImpl())._buildQuadTreeAccelerator(Geometry.GeometryAccelerationDegree.enumMedium); p_polygon_a = pa; } else { if (PointInPolygonHelper.quadTreeWillHelp(polygon_b, polygon_a.getPathCount() - 1) && (multi_path_impl_b._getAccelerators() == null || multi_path_impl_b._getAccelerators().getQuadTree() == null)) { pb = new Polygon(); polygon_b.copyTo(pb); ((MultiPathImpl) pb._getImpl())._buildQuadTreeAccelerator(Geometry.GeometryAccelerationDegree.enumMedium); p_polygon_b = pb; } else {
@Override public void write(final DataOutput dataOutput) throws IOException { final int pathCount = polygon.getPathCount(); dataOutput.writeInt(pathCount); for (int i = 0; i < pathCount; i++) { dataOutput.writeInt(polygon.getPathSize(i)); } final Point2D point2D = new Point2D(); final int pointCount = polygon.getPointCount(); for (int i = 0; i < pointCount; i++) { polygon.getXY(i, point2D); // Had to patch https://github.com/Esri/geometry-api-java dataOutput.writeDouble(point2D.x); dataOutput.writeDouble(point2D.y); } }
@Override public Geometry createInstance() { return new Polygon(getDescription()); }
getEsriGeometryCursor(), false, null); MultiPoint mp = new MultiPoint(); Polygon polygon = new Polygon(); VertexDescription vd = null; for (Geometry geom = cursor.next(); geom != null; geom = cursor.next()) { polygon.add((MultiPath) geom, false); if (!polygon.isEmpty()) { if (resultGeom != null && !resultGeom.isEmpty()) { Geometry[] geoms = { resultGeom, polygon };
private static Point2D getPolygonSansHolesCentroid(Polygon polygon) { int pointCount = polygon.getPointCount(); double xSum = 0; double ySum = 0; double signedArea = 0; Point2D current = new Point2D(); Point2D next = new Point2D(); for (int i = 0; i < pointCount; i++) { polygon.getXY(i, current); polygon.getXY((i + 1) % pointCount, next); double ladder = current.x * next.y - next.x * current.y; xSum += (current.x + next.x) * ladder; ySum += (current.y + next.y) * ladder; signedArea += ladder / 2; } return new Point2D(xSum / (signedArea * 6), ySum / (signedArea * 6)); } }
private static boolean polygonContainsPolygonImpl_(Polygon polygon_a, Polygon polygon_b, double tolerance, ProgressTracker progressTracker) { boolean[] b_result_known = new boolean[1]; b_result_known[0] = false; boolean res = polygonContainsMultiPath_(polygon_a, polygon_b, tolerance, b_result_known, progressTracker); if (b_result_known[0]) return res; // We can clip polygon_a to the extent of polyline_b Envelope2D envBInflated = new Envelope2D(); polygon_b.queryEnvelope2D(envBInflated); envBInflated.inflate(1000.0 * tolerance, 1000.0 * tolerance); Polygon _polygonA = null; if (polygon_a.getPointCount() > 10) { _polygonA = (Polygon)Clipper.clip(polygon_a, envBInflated, tolerance, 0.0); if (_polygonA.isEmpty()) return false; } else { _polygonA = polygon_a; } boolean bContains = RelationalOperationsMatrix.polygonContainsPolygon_(_polygonA, polygon_b, tolerance, progressTracker); return bContains; }
private static boolean polygonEqualsPolygon_(Polygon polygon_a, Polygon polygon_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); polygon_b.queryEnvelope2D(env_b); // Quick envelope rejection test for false equality. if (!envelopeEqualsEnvelope_(env_a, env_b, tolerance, progress_tracker)) return false; // Quick rasterize test to see whether the the geometries are disjoint, // or if one is contained in the other. int relation = tryRasterizedContainsOrDisjoint_(polygon_a, polygon_b, tolerance, false); if (relation == Relation.disjoint || relation == Relation.contains || relation == Relation.within) return false; // Quick point equality check for true equality. This just checks if all // the points in each ring are the same (within a tolerance) and in the // same order if (multiPathExactlyEqualsMultiPath_(polygon_a, polygon_b, tolerance, progress_tracker)) return true; double length_a = polygon_a.calculateLength2D(); double length_b = polygon_b.calculateLength2D(); int max_vertices = Math.max(polygon_a.getPointCount(), polygon_b.getPointCount()); if (Math.abs(length_a - length_b) > max_vertices * 4.0 * tolerance) return false; return linearPathEqualsLinearPath_(polygon_a, polygon_b, tolerance, true); }
private static boolean polygonContainsPolylineImpl_(Polygon polygon_a, Polyline polyline_b, double tolerance, ProgressTracker progress_tracker) { boolean[] b_result_known = new boolean[1]; b_result_known[0] = false; boolean res = polygonContainsMultiPath_(polygon_a, polyline_b, tolerance, b_result_known, progress_tracker); if (b_result_known[0]) return res; // We can clip polygon_a to the extent of polyline_b Envelope2D envBInflated = new Envelope2D(); polyline_b.queryEnvelope2D(envBInflated); envBInflated.inflate(1000.0 * tolerance, 1000.0 * tolerance); Polygon _polygonA = null; if (polygon_a.getPointCount() > 10) { _polygonA = (Polygon)Clipper.clip(polygon_a, envBInflated, tolerance, 0.0); if (_polygonA.isEmpty()) return false; } else { _polygonA = polygon_a; } boolean bContains = RelationalOperationsMatrix.polygonContainsPolyline_(_polygonA, polyline_b, tolerance, progress_tracker); return bContains; }