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)); }
if (polygon.getPointCount() != 4) { return false;
static boolean quadTreeWillHelp(Polygon polygon, int c_queries) { int n = polygon.getPointCount(); if (n < 16) return false; double c_build_quad_tree = 2.0; // what's a good constant? double c_query_quad_tree = 1.0; // what's a good constant? double c_point_in_polygon_brute_force = 1.0; // what's a good constant? double c_quad_tree = c_build_quad_tree * n + c_query_quad_tree * (Math.log((double)n) / Math.log(2.0)) * c_queries; double c_brute_force = c_point_in_polygon_brute_force * n * c_queries; return c_quad_tree < c_brute_force; }
static boolean quadTreeWillHelp(Polygon polygon, int c_queries) { int n = polygon.getPointCount(); if (n < 16) return false; double c_build_quad_tree = 2.0; // what's a good constant? double c_query_quad_tree = 1.0; // what's a good constant? double c_point_in_polygon_brute_force = 1.0; // what's a good constant? double c_quad_tree = c_build_quad_tree * n + c_query_quad_tree * (Math.log((double)n) / Math.log(2.0)) * c_queries; double c_brute_force = c_point_in_polygon_brute_force * n * c_queries; return c_quad_tree < c_brute_force; }
SpatialReference WGS1984 = SpatialReference.create(4326); Polygon extent = (Polygon) GeometryEngine.project( mapView.getExtent(), mapView.getSpatialReference(), WGS1984); for (int i = 0; i < extent.getPointCount(); i++) { Point corner = extent.getPoint(i); // Do something with that corner, e.g. print it... Toast.makeText(MainActivity.this, "Here's a corner: " + corner.getX() + ", " + corner.getY(), Toast.LENGTH_LONG).show(); }
public static Point getCentroid(Polygon poly) { enter code hereVector<Double> x = new Vector<Double>(); Vector<Double> y = new Vector<Double>(); for (int i = 0; i < poly.getPointCount(); i++) { x.add(poly.getPoint(i).getX()); y.add(poly.getPoint(i).getY()); } Envelope envelope = new Envelope(Collections.min(x), Collections.min(y), Collections.max(x), Collections.max(y)); return envelope.getCenter(); }
@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); } }
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 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 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)); }
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 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)); }
if (polygon.getPointCount() != 4) { return false;
if (polygon.getPointCount() != 4) { return false;
if (polygon.getPointCount() != 4) { return false;
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 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; }
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 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; }
@Override public Rectangle getMBR() { if (geom.isEmpty()) return null; com.esri.core.geometry.Polygon mbr = (com.esri.core.geometry.Polygon) geom.envelope().getEsriGeometry(); int pointCount = mbr.getPointCount(); double xmin = mbr.getPoint(0).getX(); double ymin = mbr.getPoint(0).getY(); double xmax = xmin, ymax = ymin; for (int i = 1; i < pointCount; i++) { com.esri.core.geometry.Point point = mbr.getPoint(i); if (point.getX() < xmin) xmin = point.getX(); if (point.getX() > xmax) xmax = point.getX(); if (point.getY() < ymin) ymin = point.getY(); if (point.getY() > ymax) ymax = point.getY(); } return new Rectangle(xmin, ymin, xmax, ymax); }