Skip to content

Commit 77b0c8c

Browse files
committed
Add a triangulate method to Geometry.
1 parent edbc168 commit 77b0c8c

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.locationtech.jts.geom.PrecisionModel
2424
import org.locationtech.jts.precision.GeometryPrecisionReducer
2525
import org.geotools.geometry.jts.CurvedGeometries
2626
import org.geotools.geometry.jts.OffsetCurveBuilder
27+
import org.locationtech.jts.triangulate.polygon.ConstrainedDelaunayTriangulator
2728

2829
/**
2930
* The base class for other Geometries.
@@ -154,6 +155,14 @@ class Geometry {
154155
wrap(ConcaveHullOfPolygons.concaveHullByLength(g, maxLength))
155156
}
156157

158+
/**
159+
* Triangulate the Geometry
160+
* @return A Geometry
161+
*/
162+
Geometry triangulate() {
163+
wrap(ConstrainedDelaunayTriangulator.triangulate(g))
164+
}
165+
157166
/**
158167
* Whether this Geometry is covered by the other Geometry
159168
* @param The other Geometry

src/test/groovy/geoscript/geom/GeometryTest.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,12 @@ geometry:
771771
assertEquals("Polygon", concaveHull.getGeometryType())
772772
}
773773

774+
@Test void triangulate() {
775+
Geometry geometry = Geometry.fromWKT("POLYGON ((-122.40211486816406 47.59088339146615, -122.41859436035156 47.57837853860192, -122.41172790527345 47.56540738772852, -122.39730834960938 47.55150616084034, -122.35885620117186 47.55150616084034, -122.34306335449217 47.57606249728773, -122.34718322753905 47.59551406038282, -122.3609161376953 47.58532604787685, -122.3712158203125 47.58717856130287, -122.37670898437499 47.58995720851129, -122.38494873046875 47.597366213216866, -122.39318847656249 47.59505101193038, -122.40211486816406 47.59088339146615))")
776+
Geometry triangles = geometry.triangulate()
777+
assertEquals(triangles.wkt, "GEOMETRYCOLLECTION (POLYGON ((-122.37670898437499 47.58995720851129, -122.40211486816406 47.59088339146615, -122.39318847656249 47.59505101193038, -122.37670898437499 47.58995720851129)), POLYGON ((-122.39318847656249 47.59505101193038, -122.38494873046875 47.597366213216866, -122.37670898437499 47.58995720851129, -122.39318847656249 47.59505101193038)), POLYGON ((-122.3609161376953 47.58532604787685, -122.34718322753905 47.59551406038282, -122.34306335449217 47.57606249728773, -122.3609161376953 47.58532604787685)), POLYGON ((-122.3712158203125 47.58717856130287, -122.35885620117186 47.55150616084034, -122.39730834960938 47.55150616084034, -122.3712158203125 47.58717856130287)), POLYGON ((-122.40211486816406 47.59088339146615, -122.41172790527345 47.56540738772852, -122.41859436035156 47.57837853860192, -122.40211486816406 47.59088339146615)), POLYGON ((-122.39730834960938 47.55150616084034, -122.40211486816406 47.59088339146615, -122.37670898437499 47.58995720851129, -122.39730834960938 47.55150616084034)), POLYGON ((-122.35885620117186 47.55150616084034, -122.3609161376953 47.58532604787685, -122.34306335449217 47.57606249728773, -122.35885620117186 47.55150616084034)), POLYGON ((-122.40211486816406 47.59088339146615, -122.39730834960938 47.55150616084034, -122.41172790527345 47.56540738772852, -122.40211486816406 47.59088339146615)), POLYGON ((-122.39730834960938 47.55150616084034, -122.37670898437499 47.58995720851129, -122.3712158203125 47.58717856130287, -122.39730834960938 47.55150616084034)), POLYGON ((-122.35885620117186 47.55150616084034, -122.3712158203125 47.58717856130287, -122.3609161376953 47.58532604787685, -122.35885620117186 47.55150616084034)))")
778+
}
779+
774780
@Test void covers() {
775781

776782
Polygon polygon1 = new Polygon([[

0 commit comments

Comments
 (0)