-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OverlayNG support for simple GeometryCollection inputs (#915)
Signed-off-by: Martin Davis <[email protected]>
- Loading branch information
Showing
8 changed files
with
174 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...c/test/java/org/locationtech/jts/operation/overlayng/OverlayNGGeometryCollectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.locationtech.jts.operation.overlayng; | ||
|
||
import junit.textui.TestRunner; | ||
|
||
/** | ||
* Tests supported OverlayNG semantics for GeometryCollection inputs. | ||
* | ||
* Note: currently only "simple" GCs are supported. | ||
* Simple GCs are ones which can be flattened to a valid Multi-geometry. | ||
* | ||
* @author mdavis | ||
* | ||
*/ | ||
public class OverlayNGGeometryCollectionTest extends OverlayNGTestCase { | ||
|
||
public static void main(String args[]) { | ||
TestRunner.run(OverlayNGGeometryCollectionTest.class); | ||
} | ||
|
||
public OverlayNGGeometryCollectionTest(String name) { super(name); } | ||
|
||
public void testSimpleA_mP() { | ||
String a = "POLYGON ((0 0, 0 1, 1 1, 0 0))"; | ||
String b = "GEOMETRYCOLLECTION ( MULTIPOINT ((0 0), (99 99)) )"; | ||
checkIntersection(a, b, | ||
"POINT (0 0)"); | ||
checkUnion(a, b, | ||
"GEOMETRYCOLLECTION (POINT (99 99), POLYGON ((0 0, 0 1, 1 1, 0 0)))"); | ||
} | ||
|
||
public void testSimpleP_mP() { | ||
String a = "POINT(0 0)"; | ||
String b = "GEOMETRYCOLLECTION ( MULTIPOINT ((0 0), (99 99)) )"; | ||
checkIntersection(a, b, | ||
"POINT (0 0)"); | ||
checkUnion(a, b, | ||
"MULTIPOINT ((0 0), (99 99))"); | ||
} | ||
|
||
public void testSimpleP_mL() { | ||
String a = "POINT(5 5)"; | ||
String b = "GEOMETRYCOLLECTION ( MULTILINESTRING ((1 9, 9 1), (1 1, 9 9)) )"; | ||
checkIntersection(a, b, | ||
"POINT (5 5)"); | ||
checkUnion(a, b, | ||
"MULTILINESTRING ((1 1, 5 5), (1 9, 5 5), (5 5, 9 1), (5 5, 9 9))"); | ||
} | ||
|
||
public void testSimpleP_mA() { | ||
String a = "POINT(5 5)"; | ||
String b = "GEOMETRYCOLLECTION ( MULTIPOLYGON (((1 1, 1 5, 5 5, 5 1, 1 1)), ((9 9, 9 5, 5 5, 5 9, 9 9))) )"; | ||
checkIntersection(a, b, | ||
"POINT (5 5)"); | ||
checkUnion(a, b, | ||
"MULTIPOLYGON (((1 1, 1 5, 5 5, 5 1, 1 1)), ((9 9, 9 5, 5 5, 5 9, 9 9)))"); | ||
} | ||
|
||
public void testSimpleP_AA() { | ||
String a = "POINT(5 5)"; | ||
String b = "GEOMETRYCOLLECTION ( POLYGON ((1 1, 1 5, 5 5, 5 1, 1 1)), POLYGON ((9 9, 9 5, 5 5, 5 9, 9 9)) )"; | ||
checkIntersection(a, b, | ||
"POINT (5 5)"); | ||
checkUnion(a, b, | ||
"MULTIPOLYGON (((1 1, 1 5, 5 5, 5 1, 1 1)), ((9 9, 9 5, 5 5, 5 9, 9 9)))"); | ||
} | ||
|
||
public void testSimpleL_AA() { | ||
String a = "LINESTRING (0 0, 10 10)"; | ||
String b = "GEOMETRYCOLLECTION ( POLYGON ((1 1, 1 5, 5 5, 5 1, 1 1)), POLYGON ((9 9, 9 5, 5 5, 5 9, 9 9)) )"; | ||
checkIntersection(a, b, | ||
"MULTILINESTRING ((1 1, 5 5), (5 5, 9 9))"); | ||
checkUnion(a, b, | ||
"GEOMETRYCOLLECTION (LINESTRING (0 0, 1 1), LINESTRING (9 9, 10 10), POLYGON ((1 1, 1 5, 5 5, 5 1, 1 1)), POLYGON ((5 5, 5 9, 9 9, 9 5, 5 5)))"); | ||
} | ||
|
||
public void testSimpleA_AA() { | ||
String a = "POLYGON ((2 8, 8 8, 8 2, 2 2, 2 8))"; | ||
String b = "GEOMETRYCOLLECTION ( POLYGON ((1 1, 1 5, 5 5, 5 1, 1 1)), POLYGON ((9 9, 9 5, 5 5, 5 9, 9 9)) )"; | ||
checkIntersection(a, b, | ||
"MULTIPOLYGON (((2 2, 2 5, 5 5, 5 2, 2 2)), ((5 5, 5 8, 8 8, 8 5, 5 5)))"); | ||
checkUnion(a, b, | ||
"POLYGON ((1 1, 1 5, 2 5, 2 8, 5 8, 5 9, 9 9, 9 5, 8 5, 8 2, 5 2, 5 1, 1 1))"); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
modules/core/src/test/java/org/locationtech/jts/operation/overlayng/OverlayNGTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.locationtech.jts.operation.overlayng; | ||
|
||
import static org.locationtech.jts.operation.overlayng.OverlayNG.INTERSECTION; | ||
import static org.locationtech.jts.operation.overlayng.OverlayNG.UNION; | ||
|
||
import org.locationtech.jts.geom.Geometry; | ||
import org.locationtech.jts.geom.PrecisionModel; | ||
|
||
import test.jts.GeometryTestCase; | ||
|
||
class OverlayNGTestCase extends GeometryTestCase { | ||
|
||
protected OverlayNGTestCase(String name) { | ||
super(name); | ||
} | ||
|
||
protected void checkIntersection(String wktA, String wktB, String wktExpected) { | ||
checkOverlay(wktA, wktB, INTERSECTION, wktExpected); | ||
} | ||
|
||
protected void checkUnion(String wktA, String wktB, String wktExpected) { | ||
checkOverlay(wktA, wktB, UNION, wktExpected); | ||
} | ||
|
||
protected void checkOverlay(String wktA, String wktB, int overlayOp, String wktExpected) { | ||
Geometry a = read(wktA); | ||
Geometry b = read(wktB); | ||
PrecisionModel pm = new PrecisionModel(); | ||
Geometry actual = OverlayNG.overlay(a, b, overlayOp, pm); | ||
Geometry expected = read(wktExpected); | ||
checkEqual(expected, actual); | ||
} | ||
} |