/** * Simplify the ordered points (representing a line, polygon, etc) using the * Douglas Peucker algorithm to create a similar curve with fewer points. * Points should be in a meters unit type projection. The tolerance is the * minimum tolerated distance between consecutive points. * * @param points * geometry points * @param tolerance * minimum tolerance in meters for consecutive points * @return simplified points * @since 1.0.4 */ public static List<Point> simplifyPoints(List<Point> points, double tolerance) { return simplifyPoints(points, tolerance, 0, points.size() - 1); }
/** * Check if the point is on the polygon ring edge points * * @param point * point * @param points * polygon points * @param epsilon * epsilon line tolerance * @return true if on the polygon edge * @since 1.0.5 */ public static boolean pointOnPolygonEdge(Point point, List<Point> points, double epsilon) { return pointOnPath(point, points, epsilon, !closedPolygon(points)); }
Point point = points.get(i); double d = perpendicularDistance(point, startPoint, endPoint); List<Point> recResults1 = simplifyPoints(points, tolerance, startIndex, index); List<Point> recResults2 = simplifyPoints(points, tolerance, index, endIndex);
switch (geometryType) { case LINESTRING: minimize((LineString) geometry, maxX); break; case POLYGON: minimize((Polygon) geometry, maxX); break; case MULTILINESTRING: minimize((MultiLineString) geometry, maxX); break; case MULTIPOLYGON: minimize((MultiPolygon) geometry, maxX); break; case CIRCULARSTRING: minimize((CircularString) geometry, maxX); break; case COMPOUNDCURVE: minimize((CompoundCurve) geometry, maxX); break; case CURVEPOLYGON: @SuppressWarnings("unchecked") CurvePolygon<Curve> curvePolygon = (CurvePolygon<Curve>) geometry; minimize(curvePolygon, maxX); break; case POLYHEDRALSURFACE: minimize((PolyhedralSurface) geometry, maxX); break; case TIN: minimize((TIN) geometry, maxX);
/** * Minimize the polyhedral surface * * @param polyhedralSurface * polyhedral surface * @param maxX * max positive x value in the geometry projection */ private static void minimize(PolyhedralSurface polyhedralSurface, double maxX) { for (Polygon polygon : polyhedralSurface.getPolygons()) { minimize(polygon, maxX); } }
if (closedPolygon(points)) { j = i++; contains = pointOnPolygonEdge(point, points);
/** * Get the inherent dimension (0, 1, or 2) for this Geometry * * @return dimension */ public int getDimension() { return GeometryUtils.getDimension(this); }
/** * Check if the polygon ring is explicitly closed, where the first and last * point are the same * * @param ring * polygon ring * @return true if the first and last points are the same * @since 1.0.5 */ public static boolean closedPolygon(LineString ring) { return closedPolygon(ring.getPoints()); }
/** * Get the mathematical centroid for this Geometry as a Point * * @return centroid point */ public Point getCentroid() { return GeometryUtils.getCentroid(this); }
/** * Minimize the curve polygon * * @param curvePolygon * curve polygon * @param maxX * max positive x value in the geometry projection */ private static void minimize(CurvePolygon<Curve> curvePolygon, double maxX) { for (Curve ring : curvePolygon.getRings()) { minimizeGeometry(ring, maxX); } }
/** * Add points to the centroid total * * @param points * points */ private void add(List<Point> points) { for (int i = 0; i < points.size() - 1; i++) { Point point = points.get(i); Point nextPoint = points.get(i + 1); double length = GeometryUtils.distance(point, nextPoint); totalLength += length; double midX = (point.getX() + nextPoint.getX()) / 2; sum.setX(sum.getX() + (length * midX)); double midY = (point.getY() + nextPoint.getY()) / 2; sum.setY(sum.getY() + (length * midY)); } }
/** * Minimize the polygon * * @param polygon * polygon * @param maxX * max positive x value in the geometry projection */ private static void minimize(Polygon polygon, double maxX) { for (LineString ring : polygon.getRings()) { minimize(ring, maxX); } }
List<Geometry> geometries = geomCollection.getGeometries(); for (Geometry subGeometry : geometries) { dimension = Math.max(dimension, getDimension(subGeometry));
/** * Check if the polygon outer ring is explicitly closed, where the first and * last point are the same * * @param polygon * polygon * @return true if the first and last points are the same * @since 1.0.5 */ public static boolean closedPolygon(Polygon polygon) { return polygon.numRings() > 0 && closedPolygon(polygon.getRings().get(0)); }
simplifiedPoints = GeometryUtils.simplifyPoints(points, simplifyTolerance);
/** * Minimize the compound curve * * @param compoundCurve * compound curve * @param maxX * max positive x value in the geometry projection */ private static void minimize(CompoundCurve compoundCurve, double maxX) { for (LineString lineString : compoundCurve.getLineStrings()) { minimize(lineString, maxX); } }
/** * Get the centroid point of the Geometry * * @param geometry * geometry object * @return centroid point */ public static Point getCentroid(Geometry geometry) { Point centroid = null; int dimension = getDimension(geometry); switch (dimension) { case 0: CentroidPoint point = new CentroidPoint(geometry); centroid = point.getCentroid(); break; case 1: CentroidCurve curve = new CentroidCurve(geometry); centroid = curve.getCentroid(); break; case 2: CentroidSurface surface = new CentroidSurface(geometry); centroid = surface.getCentroid(); break; } return centroid; }