Skip to content

Commit 5bca8c1

Browse files
committed
Add a Geometry method to fix invalid geometry
1 parent e4faa11 commit 5bca8c1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/main/groovy/geoscript/geom/Geometry.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.locationtech.jts.geom.prep.PreparedGeometryFactory
99
import org.locationtech.jts.geom.Envelope
1010
import org.locationtech.jts.geom.IntersectionMatrix
1111
import org.locationtech.jts.geom.util.AffineTransformation
12+
import org.locationtech.jts.geom.util.GeometryFixer
1213
import org.locationtech.jts.operation.buffer.BufferParameters
1314
import org.locationtech.jts.operation.buffer.BufferOp
1415
import org.locationtech.jts.awt.FontGlyphReader
@@ -478,6 +479,14 @@ class Geometry {
478479
wrap(this.g.union(other.g))
479480
}
480481

482+
/**
483+
* Fix an invalid Geometry
484+
* @return A new fixed Geometry
485+
*/
486+
Geometry fix() {
487+
wrap(GeometryFixer.fix(this.g))
488+
}
489+
481490
/**
482491
* Whether this Geometry is within the other Geometry
483492
* @param other The other Geometry

src/test/groovy/geoscript/geom/GeometryTestCase.groovy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,4 +1351,11 @@ class GeometryTestCase {
13511351
assertTrue(preparedGeom instanceof PreparedGeometry)
13521352
assertEquals(geom.toString(), preparedGeom.toString())
13531353
}
1354+
1355+
@Test void fix() {
1356+
Geometry invalidLine = new LineString([[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1]])
1357+
Geometry fixedLine = invalidLine.fix()
1358+
assertEquals("LINESTRING (0 0, 1 1)", fixedLine.wkt)
1359+
}
1360+
13541361
}

0 commit comments

Comments
 (0)