From da65acd4d3d0b4ab8ca6fec333c50a891609dba2 Mon Sep 17 00:00:00 2001 From: FObermaier Date: Thu, 25 Jan 2024 09:25:51 +0100 Subject: [PATCH] Line endings --- .../DouglasPeuckerLineSimplifier.java | 8 +-- .../simplify/DouglasPeuckerSimplifier.java | 38 ++++++------ .../jts/simplify/TaggedLineString.java | 14 ++--- .../simplify/TaggedLineStringSimplifier.java | 52 ++++++++-------- .../TopologyPreservingSimplifier.java | 32 +++++----- .../TopologyPreservingSimplifierTest.java | 62 +++++++++---------- 6 files changed, 102 insertions(+), 104 deletions(-) diff --git a/modules/core/src/main/java/org/locationtech/jts/simplify/DouglasPeuckerLineSimplifier.java b/modules/core/src/main/java/org/locationtech/jts/simplify/DouglasPeuckerLineSimplifier.java index 5b0441367..1677c8b2a 100644 --- a/modules/core/src/main/java/org/locationtech/jts/simplify/DouglasPeuckerLineSimplifier.java +++ b/modules/core/src/main/java/org/locationtech/jts/simplify/DouglasPeuckerLineSimplifier.java @@ -56,7 +56,7 @@ public void setDistanceTolerance(double distanceTolerance) { private void setPreserveEndpoint(boolean isPreserveEndpoint) { this.isPreserveEndpoint = isPreserveEndpoint; } - + public Coordinate[] simplify() { usePt = new boolean[pts.length]; @@ -64,13 +64,13 @@ public Coordinate[] simplify() usePt[i] = true; } simplifySection(0, pts.length - 1); - + CoordinateList coordList = new CoordinateList(); for (int i = 0; i < pts.length; i++) { if (usePt[i]) coordList.add(new Coordinate(pts[i])); } - + if (! isPreserveEndpoint && CoordinateArrays.isRing(pts)) { simplifyRingEndpoint(coordList); } @@ -84,7 +84,7 @@ private void simplifyRingEndpoint(CoordinateList pts) { return; //-- base segment for endpoint seg.p0 = pts.get(1); - seg.p1 = pts.get(pts.size() - 2); + seg.p1 = pts.get(pts.size() - 2); double distance = seg.distance(pts.get(0)); if (distance <= distanceTolerance) { pts.remove(0); diff --git a/modules/core/src/main/java/org/locationtech/jts/simplify/DouglasPeuckerSimplifier.java b/modules/core/src/main/java/org/locationtech/jts/simplify/DouglasPeuckerSimplifier.java index 5e4b4836a..b149216fe 100644 --- a/modules/core/src/main/java/org/locationtech/jts/simplify/DouglasPeuckerSimplifier.java +++ b/modules/core/src/main/java/org/locationtech/jts/simplify/DouglasPeuckerSimplifier.java @@ -24,7 +24,7 @@ * Simplifies a {@link Geometry} using the Douglas-Peucker algorithm. * Ensures that any polygonal geometries returned are valid. * Simple lines are not guaranteed to remain simple after simplification. - * All geometry types are handled. + * All geometry types are handled. * Empty and point geometries are returned unchanged. * Empty geometry components are deleted. *

@@ -49,7 +49,7 @@ public class DouglasPeuckerSimplifier /** * Simplifies a geometry using a given tolerance. - * + * * @param geom geometry to simplify * @param distanceTolerance the tolerance to use * @return a simplified version of the geometry @@ -64,10 +64,10 @@ public static Geometry simplify(Geometry geom, double distanceTolerance) private final Geometry inputGeom; private double distanceTolerance; private boolean isEnsureValidTopology = true; - + /** * Creates a simplifier for a given geometry. - * + * * @param inputGeom the geometry to simplify */ public DouglasPeuckerSimplifier(Geometry inputGeom) @@ -79,7 +79,7 @@ public DouglasPeuckerSimplifier(Geometry inputGeom) * Sets the distance tolerance for the simplification. * All vertices in the simplified geometry will be within this * distance of the original geometry. - * The tolerance value must be non-negative. + * The tolerance value must be non-negative. * * @param distanceTolerance the approximation tolerance to use */ @@ -98,26 +98,26 @@ public void setDistanceTolerance(double distanceTolerance) { *

  • fixing topology is a relative expensive operation *
  • in some pathological cases the topology fixing operation may either fail or run for too long * - * + * * The default is to fix polygon topology. - * + * * @param isEnsureValidTopology */ public void setEnsureValid(boolean isEnsureValidTopology) { this.isEnsureValidTopology = isEnsureValidTopology; } - + /** * Gets the simplified geometry. - * + * * @return the simplified geometry */ public Geometry getResultGeometry() { // empty input produces an empty result if (inputGeom.isEmpty()) return inputGeom.copy(); - + return (new DPTransformer(isEnsureValidTopology, distanceTolerance)).transform(inputGeom); } @@ -132,12 +132,12 @@ public DPTransformer(boolean isEnsureValidTopology, double distanceTolerance) this.isEnsureValidTopology = isEnsureValidTopology; this.distanceTolerance = distanceTolerance; } - + protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) { boolean isPreserveEndpoint = ! (parent instanceof LinearRing); Coordinate[] inputPts = coords.toCoordinateArray(); - Coordinate[] newPts = null; + Coordinate[] newPts; if (inputPts.length == 0) { newPts = new Coordinate[0]; } @@ -163,13 +163,12 @@ protected Geometry transformPolygon(Polygon geom, Geometry parent) { } /** - * Simplifies a LinearRing. If the simplification results + * Simplifies a LinearRing. If the simplification results * in a degenerate ring, remove the component. - * + * * @return null if the simplification results in a degenerate ring */ - //* - protected Geometry transformLinearRing(LinearRing geom, Geometry parent) + protected Geometry transformLinearRing(LinearRing geom, Geometry parent) { boolean removeDegenerateRings = parent instanceof Polygon; Geometry simpResult = super.transformLinearRing(geom, parent); @@ -177,8 +176,7 @@ protected Geometry transformLinearRing(LinearRing geom, Geometry parent) return null; return simpResult; } - //*/ - + /** * Simplifies a MultiPolygon, fixing it if required. */ @@ -195,8 +193,8 @@ protected Geometry transformMultiPolygon(MultiPolygon geom, Geometry parent) { * topology. * Note this only works for area geometries, since buffer always returns * areas. This also may return empty geometries, if the input - * has no actual area. - * If the input is empty or is not polygonal, + * has no actual area. + * If the input is empty or is not polygonal, * this ensures that POLYGON EMPTY is returned. * * @param rawAreaGeom an area geometry possibly containing self-intersections diff --git a/modules/core/src/main/java/org/locationtech/jts/simplify/TaggedLineString.java b/modules/core/src/main/java/org/locationtech/jts/simplify/TaggedLineString.java index ad262d29a..ffa06a49f 100644 --- a/modules/core/src/main/java/org/locationtech/jts/simplify/TaggedLineString.java +++ b/modules/core/src/main/java/org/locationtech/jts/simplify/TaggedLineString.java @@ -21,10 +21,10 @@ import org.locationtech.jts.geom.LinearRing; /** - * Represents a {@link LineString} which can be modified to a simplified shape. + * Represents a {@link LineString} which can be modified to a simplified shape. * This class provides an attribute which specifies the minimum allowable length * for the modified result. - * + * * @version 1.7 */ class TaggedLineString @@ -46,8 +46,8 @@ public TaggedLineString(LineString parentLine, int minimumSize, boolean isRing) public boolean isRing() { return isRing; } - - public int getMinimumSize() { return minimumSize; } + + public int getMinimumSize() { return minimumSize; } public LineString getParent() { return parentLine; } public Coordinate[] getParentCoordinates() { return parentLine.getCoordinates(); } public Coordinate[] getResultCoordinates() { return extractCoordinates(resultSegs); } @@ -59,11 +59,11 @@ public Coordinate getCoordinate(int i) { public int size() { return parentLine.getNumPoints(); } - + public Coordinate getComponentPoint() { return getParentCoordinates()[1]; } - + public int getResultSize() { int resultSegsSize = resultSegs.size(); @@ -102,7 +102,7 @@ private void init() * Add a simplified segment to the result. * This assumes simplified segments are computed in the order * they occur in the line. - * + * * @param seg the result segment to add */ public void addToResult(LineSegment seg) diff --git a/modules/core/src/main/java/org/locationtech/jts/simplify/TaggedLineStringSimplifier.java b/modules/core/src/main/java/org/locationtech/jts/simplify/TaggedLineStringSimplifier.java index fe4919b72..95b74ab84 100644 --- a/modules/core/src/main/java/org/locationtech/jts/simplify/TaggedLineStringSimplifier.java +++ b/modules/core/src/main/java/org/locationtech/jts/simplify/TaggedLineStringSimplifier.java @@ -40,7 +40,7 @@ public class TaggedLineStringSimplifier private Coordinate[] linePts; public TaggedLineStringSimplifier(LineSegmentIndex inputIndex, - LineSegmentIndex outputIndex, + LineSegmentIndex outputIndex, ComponentJumpChecker crossChecker) { this.inputIndex = inputIndex; @@ -51,7 +51,7 @@ public TaggedLineStringSimplifier(LineSegmentIndex inputIndex, /** * Simplifies the given {@link TaggedLineString} * using the distance tolerance specified. - * + * * @param line the linestring to simplify * @param distanceTolerance the simplification distance tolerance */ @@ -60,7 +60,7 @@ void simplify(TaggedLineString line, double distanceTolerance) this.line = line; linePts = line.getParentCoordinates(); simplifySection(0, linePts.length - 1, 0, distanceTolerance); - + if (line.isRing() && CoordinateArrays.isRing(linePts)) { simplifyRingEndpoint(distanceTolerance); } @@ -94,12 +94,12 @@ private void simplifySection(int i, int j, int depth, double distanceTolerance) double[] distance = new double[1]; int furthestPtIndex = findFurthestPoint(linePts, i, j, distance); - + // flattening must be less than distanceTolerance if (distance[0] > distanceTolerance) { isValidToSimplify = false; } - + if (isValidToSimplify) { // test if flattened section would cause intersection or jump LineSegment flatSeg = new LineSegment(); @@ -107,7 +107,7 @@ private void simplifySection(int i, int j, int depth, double distanceTolerance) flatSeg.p1 = linePts[j]; isValidToSimplify = isTopologyValid(line, i, j, flatSeg); } - + if (isValidToSimplify) { LineSegment newSeg = flatten(i, j); line.addToResult(newSeg); @@ -163,7 +163,7 @@ private int findFurthestPoint(Coordinate[] pts, int i, int j, double[] maxDistan * replacing them with a line between the endpoints. * The input and output indexes are updated * to reflect this. - * + * * @param start the start index of the flattened section * @param end the end index of the flattened section * @return the new segment created @@ -177,16 +177,16 @@ private LineSegment flatten(int start, int end) // update the input and output indexes outputIndex.add(newSeg); remove(line, start, end); - + return newSeg; } /** * Tests if line topology remains valid after flattening a section of the line. - * The flattened section is being replaced by the flattening segment, - * so there is no need to test it + * The flattened section is being replaced by the flattening segment, + * so there is no need to test it * (and it may well intersect the segment). - * + * * @param line * @param sectionStart * @param sectionEnd @@ -197,11 +197,11 @@ private boolean isTopologyValid(TaggedLineString line, int sectionStart, int sectionEnd, LineSegment flatSeg) { - if (hasOutputIntersection(flatSeg)) + if (hasOutputIntersection(flatSeg)) return false; - if (hasInputIntersection(line, sectionStart, sectionEnd, flatSeg)) + if (hasInputIntersection(line, sectionStart, sectionEnd, flatSeg)) return false; - if (jumpChecker.hasJump(line, sectionStart, sectionEnd, flatSeg)) + if (jumpChecker.hasJump(line, sectionStart, sectionEnd, flatSeg)) return false; return true; } @@ -210,17 +210,17 @@ private boolean isTopologyValid(TaggedLineString line, LineSegment seg1, LineSeg LineSegment flatSeg) { //-- if segments are already flat, topology is unchanged and so is valid //-- (otherwise, output and/or input intersection test would report false positive) - if (isCollinear(seg1.p0, flatSeg)) + if (isCollinear(seg1.p0, flatSeg)) return true; - if (hasOutputIntersection(flatSeg)) + if (hasOutputIntersection(flatSeg)) return false; - if (hasInputIntersection(flatSeg)) + if (hasInputIntersection(flatSeg)) return false; - if (jumpChecker.hasJump(line, seg1, seg2, flatSeg)) + if (jumpChecker.hasJump(line, seg1, seg2, flatSeg)) return false; return true; } - + private boolean isCollinear(Coordinate pt, LineSegment seg) { return Orientation.COLLINEAR == seg.orientationIndex(pt); } @@ -241,7 +241,7 @@ private boolean hasInputIntersection(LineSegment flatSeg) { return hasInputIntersection(null, -1, -1, flatSeg); } - + private boolean hasInputIntersection(TaggedLineString line, int excludeStart, int excludeEnd, LineSegment flatSeg) @@ -250,11 +250,11 @@ private boolean hasInputIntersection(TaggedLineString line, for (Iterator i = querySegs.iterator(); i.hasNext(); ) { TaggedLineSegment querySeg = (TaggedLineSegment) i.next(); if (hasInvalidIntersection(querySeg, flatSeg)) { - /** + /* * Ignore the intersection if the intersecting segment is part of the section being collapsed * to the candidate segment */ - if (line != null + if (line != null && isInLineSection(line, excludeStart, excludeEnd, querySeg)) continue; return true; @@ -265,12 +265,12 @@ && isInLineSection(line, excludeStart, excludeEnd, querySeg)) /** * Tests whether a segment is in a section of a TaggedLineString. - * Sections may wrap around the endpoint of the line, + * Sections may wrap around the endpoint of the line, * to support ring endpoint simplification. * This is indicated by excludedStart > excludedEnd - * + * * @param line the TaggedLineString containing the section segments - * @param excludeStart the index of the first segment in the excluded section + * @param excludeStart the index of the first segment in the excluded section * @param excludeEnd the index of the last segment in the excluded section * @param seg the segment to test * @return true if the test segment intersects some segment in the line not in the excluded section @@ -292,7 +292,7 @@ private static boolean isInLineSection( else { //-- section wraps around the end of a ring if (segIndex >= excludeStart || segIndex <= excludeEnd) - return true; + return true; } return false; } diff --git a/modules/core/src/main/java/org/locationtech/jts/simplify/TopologyPreservingSimplifier.java b/modules/core/src/main/java/org/locationtech/jts/simplify/TopologyPreservingSimplifier.java index 2703dff42..155306a12 100644 --- a/modules/core/src/main/java/org/locationtech/jts/simplify/TopologyPreservingSimplifier.java +++ b/modules/core/src/main/java/org/locationtech/jts/simplify/TopologyPreservingSimplifier.java @@ -36,9 +36,9 @@ *
  • The result has the same number of shells and holes as the input, * with the same topological structure *
  • The result rings touch at no more than the number of touching points in the input - * (although they may touch at fewer points). - * The key implication of this statement is that if the - * input is topologically valid, so is the simplified output. + * (although they may touch at fewer points). + * The key implication of this statement is that if the + * input is topologically valid, so is the simplified output. * * For linear geometries, if the input does not contain * any intersecting line segments, this property @@ -47,19 +47,19 @@ * For polygonal geometries and LinearRings the ring endpoint will be simplified. * For LineStrings the endpoints will be unchanged. *

    - * For all geometry types, the result will contain + * For all geometry types, the result will contain * enough vertices to ensure validity. For polygons * and closed linear geometries, the result will have at * least 4 vertices; for open linestrings the result * will have at least 2 vertices. *

    - * All geometry types are handled. + * All geometry types are handled. * Empty and point geometries are returned unchanged. * Empty geometry components are deleted. *

    * The simplification uses a maximum-distance difference algorithm * similar to the Douglas-Peucker algorithm. - * + * * @author Martin Davis * @see DouglasPeuckerSimplifier * @@ -97,11 +97,11 @@ public void setDistanceTolerance(double distanceTolerance) { lineSimplifier.setDistanceTolerance(distanceTolerance); } - public Geometry getResultGeometry() + public Geometry getResultGeometry() { // empty input produces an empty result if (inputGeom.isEmpty()) return inputGeom.copy(); - + linestringMap = new HashMap(); inputGeom.apply(new LineStringMapBuilderFilter(this)); lineSimplifier.simplify(linestringMap.values()); @@ -117,7 +117,7 @@ static class LineStringTransformer public LineStringTransformer(Map linestringMap) { this.linestringMap = linestringMap; } - + protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) { if (coords.size() == 0) return null; @@ -132,13 +132,13 @@ protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geo } /** - * A filter to add linear geometries to the linestring map + * A filter to add linear geometries to the linestring map * with the appropriate minimum size constraint. * Closed {@link LineString}s (including {@link LinearRing}s - * have a minimum output size constraint of 4, + * have a minimum output size constraint of 4, * to ensure the output is valid. * For all other linestrings, the minimum size is 2 points. - * + * * @author Martin Davis * */ @@ -146,15 +146,15 @@ static class LineStringMapBuilderFilter implements GeometryComponentFilter { TopologyPreservingSimplifier tps; - + LineStringMapBuilderFilter(TopologyPreservingSimplifier tps) { this.tps = tps; } - + /** * Filters linear geometries. - * - * geom a geometry of any type + * + * @param geom a geometry of any type */ public void filter(Geometry geom) { diff --git a/modules/core/src/test/java/org/locationtech/jts/simplify/TopologyPreservingSimplifierTest.java b/modules/core/src/test/java/org/locationtech/jts/simplify/TopologyPreservingSimplifierTest.java index f06a6d001..784f44672 100644 --- a/modules/core/src/test/java/org/locationtech/jts/simplify/TopologyPreservingSimplifierTest.java +++ b/modules/core/src/test/java/org/locationtech/jts/simplify/TopologyPreservingSimplifierTest.java @@ -34,90 +34,90 @@ public static void main(String[] args) { public void testPoint() { checkTPSNoChange("POINT (10 10)", 1); } - + public void testPolygonEmpty() { checkTPSNoChange("POLYGON(EMPTY)", 1); } - + public void testPolygonFlatVertices() throws Exception { checkTPS("POLYGON ((20 220, 40 220, 60 220, 80 220, 100 220, 120 220, 140 220, 140 180, 100 180, 60 180, 20 180, 20 220))", 10, "POLYGON ((20 220, 140 220, 140 180, 20 180, 20 220))"); } - + public void testPolygonNoReduction() throws Exception { checkTPSNoChange("POLYGON ((20 220, 140 220, 140 180, 20 180, 20 220))", 10); } - + public void testPolygonNoReductionWithConflicts() throws Exception { checkTPSNoChange("POLYGON ((40 240, 160 241, 280 240, 280 160, 160 240, 40 140, 40 240))", 10); } - + public void testPolygonWithTouchingHole() throws Exception { checkTPS("POLYGON ((80 200, 240 200, 240 60, 80 60, 80 200), (120 120, 220 120, 180 199, 160 200, 140 199, 120 120))", 10, "POLYGON ((80 200, 240 200, 240 60, 80 60, 80 200), (120 120, 220 120, 180 199, 160 200, 140 199, 120 120))"); } - + public void testFlattishPolygon() throws Exception { checkTPS("POLYGON ((0 0, 50 0, 53 0, 55 0, 100 0, 70 1, 60 1, 50 1, 40 1, 0 0))", 10, "POLYGON ((0 0, 50 0, 100 0, 70 1, 0 0))"); } - + public void testPolygonWithFlattishHole() throws Exception { checkTPS("POLYGON ((0 0, 0 200, 200 200, 200 0, 0 0), (140 40, 90 95, 40 160, 95 100, 140 40))", 20, "POLYGON ((0 0, 0 200, 200 200, 200 0, 0 0), (140 40, 90 95, 40 160, 95 100, 140 40))"); } - + public void testTinySquare() throws Exception { checkTPS("POLYGON ((0 5, 5 5, 5 0, 0 0, 0 1, 0 5))", 10, "POLYGON ((0 0, 5 5, 5 0, 0 0))"); } - + public void testTinyLineString() throws Exception { checkTPS("LINESTRING (0 5, 1 5, 2 5, 5 5)", 10, "LINESTRING (0 5, 5 5)"); } - + public void testTinyClosedLineString() throws Exception { checkTPSNoChange("LINESTRING (0 0, 5 0, 5 5, 0 0)", 10); } - + public void testMultiPoint() throws Exception { checkTPSNoChange("MULTIPOINT(80 200, 240 200, 240 60, 80 60, 80 200, 140 199, 120 120)", 10); } - + public void testMultiLineString() throws Exception { checkTPS("MULTILINESTRING( (0 0, 50 0, 70 0, 80 0, 100 0), (0 0, 50 1, 60 1, 100 0) )", 10, "MULTILINESTRING ((0 0, 100 0), (0 0, 50 1, 100 0))"); } - + public void testMultiLineStringWithEmpty() throws Exception { checkTPS("MULTILINESTRING(EMPTY, (0 0, 50 0, 70 0, 80 0, 100 0), (0 0, 50 1, 60 1, 100 0) )", 10, "MULTILINESTRING ((0 0, 100 0), (0 0, 50 1, 100 0))"); } - + public void testMultiPolygonWithEmpty() throws Exception { checkTPS("MULTIPOLYGON (EMPTY, ((10 90, 10 10, 90 10, 50 60, 10 90)), ((70 90, 90 90, 90 70, 70 70, 70 90)))", 10, "MULTIPOLYGON (((10 90, 10 10, 90 10, 50 60, 10 90)), ((70 90, 90 90, 90 70, 70 70, 70 90)))"); } - + public void testGeometryCollection() { checkTPSNoChange("GEOMETRYCOLLECTION (MULTIPOINT (80 200, 240 200, 240 60, 80 60, 80 200, 140 199, 120 120), POLYGON ((80 200, 240 200, 240 60, 80 60, 80 200)), LINESTRING (80 200, 240 200, 240 60, 80 60, 80 200, 140 199, 120 120))", 10); } - + public void testNoCollapse_mL() throws Exception { checkTPS( "MULTILINESTRING ((0 0, 100 0), (0 0, 60 1, 100 0))", @@ -141,7 +141,7 @@ public void testNoCollapseSmallSquare() throws Exception { "POLYGON ((0 0, 5 5, 5 0, 0 0))" ); } - + public void testPolygonRemoveEndpoint() throws Exception { checkTPS( "POLYGON ((220 180, 261 175, 380 220, 300 40, 140 30, 30 220, 176 176, 220 180))", @@ -149,7 +149,7 @@ public void testPolygonRemoveEndpoint() throws Exception { "POLYGON ((30 220, 380 220, 300 40, 140 30, 30 220))" ); } - + public void testLinearRingRemoveEndpoint() throws Exception { checkTPS( "LINEARRING (220 180, 261 175, 380 220, 300 40, 140 30, 30 220, 176 176, 220 180)", @@ -162,12 +162,12 @@ public void testLinearRingRemoveEndpoint() throws Exception { "LINESTRING (30 220, 380 220, 300 40, 140 30, 30 220)" ); } - + public void testPolygonKeepFlatEndpointWithTouch() throws Exception { checkTPSNoChange("POLYGON ((0 0, 5 2.05, 10 0, 10 10, 0 10, 0 0), (5 2.1, 6 2, 6 4, 4 4, 4 2, 5 2.1))", 0.1 ); } - + public void testPolygonKeepEndpointWithCross() throws Exception { checkTPS( "POLYGON ((50 52, 60 50, 90 60, 90 10, 10 10, 10 90, 60 90, 50 55, 40 80, 20 60, 40 50, 50 52))", @@ -175,7 +175,7 @@ public void testPolygonKeepEndpointWithCross() throws Exception { "POLYGON ((20 60, 50 52, 90 60, 90 10, 10 10, 10 90, 60 90, 50 55, 40 80, 20 60))" ); } - + // see https://trac.osgeo.org/geos/ticket/1064 public void testPolygonRemoveFlatEndpoint() throws Exception { checkTPS( @@ -192,8 +192,8 @@ public void testPolygonManyFlatSegments() throws Exception { "POLYGON ((9 5, 9 1, 1 1, 1 5, 9 5))" ); } - - //-- vertex is not removed due to overly-restrictive heuristic result length calculation? + + //-- vertex is not removed due to overly-restrictive heuristic result length calculation? public void testPolygonSize5NotSimplfied() throws Exception { checkTPS( "POLYGON ((10 90, 10 10, 90 10, 47 57, 10 90))", @@ -201,12 +201,12 @@ public void testPolygonSize5NotSimplfied() throws Exception { "POLYGON ((10 90, 10 10, 90 10, 47 57, 10 90))" ); } - + /** * Test is from http://postgis.refractions.net/pipermail/postgis-users/2008-April/019327.html * Exhibits the issue where simplified polygon shells can "jump" across * holes, causing invalid topology. - * + * * @throws Exception */ public void testMultiPolygonWithSmallComponents() throws Exception { @@ -214,7 +214,7 @@ public void testMultiPolygonWithSmallComponents() throws Exception { 0.0057, "MULTIPOLYGON (((13.73095 51.024734, 13.7123153 51.041449, 13.7412027 51.0463256, 13.7552745 51.0566237, 13.7484397 51.0324582, 13.73095 51.024734)), ((13.7390933 51.0471421, 13.7369099 51.0474154, 13.7390933 51.047209, 13.7390933 51.0471421)), ((13.7367293 51.0470057, 13.7346615 51.0466892, 13.7347106 51.0471899, 13.7367293 51.0470057)))"); } - + /** * Test is from http://lists.jump-project.org/pipermail/jts-devel/2008-February/002350.html * @throws Exception @@ -224,25 +224,25 @@ public void testPolygonWithSpike() throws Exception { 2, "POLYGON ((3312459.605 6646878.353, 3312460.524 6646875.969, 3312459.427 6646878.421, 3312460.014 6646886.391, 3312465.889 6646887.398, 3312470.827 6646884.839, 3312477.289 6646871.694, 3312472.748 6646869.547, 3312459.605 6646878.353))"); } - + public void testLineComponentCross() { checkTPS("MULTILINESTRING ((0 0, 10 2, 20 0), (9 1, 11 1))", 4, "MULTILINESTRING ((0 0, 10 2, 20 0), (9 1, 11 1))"); } - + public void testPolygonComponentCrossAtEndpoint() { checkTPS("MULTIPOLYGON (((50 40, 40 60, 80 40, 0 0, 30 70, 50 40)), ((40 56, 40 57, 41 56, 40 56)))", 30, "MULTIPOLYGON (((50 40, 80 40, 0 0, 30 70, 50 40)), ((40 56, 40 57, 41 56, 40 56)))"); } - + public void testPolygonIntersectingSegments() { checkTPS("MULTIPOLYGON (((0.63 0.2, 0.35 0, 0.73 0.66, 0.63 0.2)), ((1.42 4.01, 3.45 0.7, 1.79 1.47, 0 0.57, 1.42 4.01)))", 10, "MULTIPOLYGON (((0.63 0.2, 0.35 0, 0.73 0.66, 0.63 0.2)), ((1.42 4.01, 3.45 0.7, 1.79 1.47, 0 0.57, 1.42 4.01)))"); } - + private void checkTPS(String wkt, double tolerance, String wktExpected) { Geometry geom = read(wkt); Geometry actual = TopologyPreservingSimplifier.simplify(geom, tolerance); @@ -251,7 +251,7 @@ private void checkTPS(String wkt, double tolerance, String wktExpected) { //checkValid(actual); checkEqual(expected, actual); } - + private void checkTPSNoChange(String wkt, double tolerance) { checkTPS(wkt, tolerance, wkt); }