Skip to content

Commit

Permalink
check validity and repair with locationtech/jts#682
Browse files Browse the repository at this point in the history
  • Loading branch information
Cavva79 committed Feb 8, 2021
1 parent 2406fe1 commit d1d8892
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>1.16.1</version>
<version>1.18.1-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
36 changes: 34 additions & 2 deletions src/test/java/geometry/test/GeometryTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package geometry.test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.WKTReader;

public class GeometryTest {

private static WKTReader reader;

@BeforeAll
Expand All @@ -16,12 +18,42 @@ public static void initTests() {
}

@Test
public void testFixGeometry() throws Exception {
public void testReadGeometry() throws Exception {
String wktError = "MULTIPOLYGON ("
+ "((1764821.349985 4897058.789998, 1764821.349425 4897058.794803, 1764821.349985 4897058.789998)), "
+ "((1764821.34997 4897058.789997, 1764818.68 4897058.5, 1764812.591783 4897057.108204, 1764819.560837 4896999.356852, 1764801.447089 4896996.63796, 1764802.126355 4896987.574986, 1764827.938445 4896990.067304, 1764830.429086 4896964.011253, 1764832.740144 4896964.29157, 1764832.226208 4896968.528816, 1764833.728522 4896968.674128, 1764833.726376 4896968.721375, 1764832.22 4896968.58, 1764823.96 4897035.76, 1764826.244162 4897035.937929, 1764826.243892 4897035.940238, 1764823.961426 4897035.762083, 1764821.34997 4897058.789997))"
+ ")";
Geometry geometry = reader.read(wktError);
assertFalse(geometry.isValid(), "Valid geometry");
}

@Test
public void testReadGeometryValid() throws Exception {
String wktError = "MULTIPOLYGON ("
+ "((1764821.34997 4897058.789997, 1764818.68 4897058.5, 1764812.591783 4897057.108204, 1764819.560837 4896999.356852, 1764801.447089 4896996.63796, 1764802.126355 4896987.574986, 1764827.938445 4896990.067304, 1764830.429086 4896964.011253, 1764832.740144 4896964.29157, 1764832.226208 4896968.528816, 1764833.728522 4896968.674128, 1764833.726376 4896968.721375, 1764832.22 4896968.58, 1764823.96 4897035.76, 1764826.244162 4897035.937929, 1764826.243892 4897035.940238, 1764823.961426 4897035.762083, 1764821.34997 4897058.789997))"
+ ")";
Geometry geometry = reader.read(wktError);
assertTrue(geometry.isValid(), "Invalid geometry");
}

@Test
public void testFixGeometryWithBuffer0() throws Exception {
String wktError = "MULTIPOLYGON ("
+ "((1764821.349985 4897058.789998, 1764821.349425 4897058.794803, 1764821.349985 4897058.789998)), "
+ "((1764821.34997 4897058.789997, 1764818.68 4897058.5, 1764812.591783 4897057.108204, 1764819.560837 4896999.356852, 1764801.447089 4896996.63796, 1764802.126355 4896987.574986, 1764827.938445 4896990.067304, 1764830.429086 4896964.011253, 1764832.740144 4896964.29157, 1764832.226208 4896968.528816, 1764833.728522 4896968.674128, 1764833.726376 4896968.721375, 1764832.22 4896968.58, 1764823.96 4897035.76, 1764826.244162 4897035.937929, 1764826.243892 4897035.940238, 1764823.961426 4897035.762083, 1764821.34997 4897058.789997))"
+ ")";
Geometry geometry = reader.read(wktError).buffer(0);
assertTrue(geometry.isValid(), "Invalid geometry");
}

@Test
public void testFixGeometryWithSelfUnion() throws Exception {
String wktError = "MULTIPOLYGON ("
+ "((1764821.349985 4897058.789998, 1764821.349425 4897058.794803, 1764821.349985 4897058.789998)), "
+ "((1764821.34997 4897058.789997, 1764818.68 4897058.5, 1764812.591783 4897057.108204, 1764819.560837 4896999.356852, 1764801.447089 4896996.63796, 1764802.126355 4896987.574986, 1764827.938445 4896990.067304, 1764830.429086 4896964.011253, 1764832.740144 4896964.29157, 1764832.226208 4896968.528816, 1764833.728522 4896968.674128, 1764833.726376 4896968.721375, 1764832.22 4896968.58, 1764823.96 4897035.76, 1764826.244162 4897035.937929, 1764826.243892 4897035.940238, 1764823.961426 4897035.762083, 1764821.34997 4897058.789997))"
+ ")";
Geometry geometry = reader.read(wktError);
geometry = geometry.union(geometry);
assertTrue(geometry.isValid(), "Invalid geometry");
}

Expand Down

0 comments on commit d1d8892

Please sign in to comment.