Skip to content

Commit edbc168

Browse files
committed
Add concave hull of polygons method to Geometry.
1 parent 28daaa8 commit edbc168

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package geoscript.geom
33
import org.locationtech.jts.algorithm.construct.LargestEmptyCircle
44
import org.locationtech.jts.algorithm.construct.MaximumInscribedCircle
55
import org.locationtech.jts.algorithm.hull.ConcaveHull
6+
import org.locationtech.jts.algorithm.hull.ConcaveHullOfPolygons
67
import org.locationtech.jts.geom.Geometry as JtsGeometry
78
import org.locationtech.jts.geom.GeometryFactory
89
import org.locationtech.jts.geom.Coordinate
@@ -144,6 +145,15 @@ class Geometry {
144145
wrap(ConcaveHull.concaveHullByLength(g, maxLength))
145146
}
146147

148+
/**
149+
* Calculate the concave hull of polygons
150+
* @param maxLength The max length
151+
* @return A Geometry
152+
*/
153+
Geometry concaveHullOfPolygons(double maxLength = 0.0) {
154+
wrap(ConcaveHullOfPolygons.concaveHullByLength(g, maxLength))
155+
}
156+
147157
/**
148158
* Whether this Geometry is covered by the other Geometry
149159
* @param The other Geometry

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,17 @@ geometry:
760760
"-122.3876953125 47.58121554959838))", concaveHull.wkt)
761761
}
762762

763+
@Test void concaveHullOfPolygons() {
764+
Geometry geometry = Geometry.fromWKT("MULTIPOLYGON(" +
765+
"((-122.38706231117247 47.5819609632087, -122.38846778869627 47.581338579760555, -122.3865258693695 47.58132410563883, -122.3874270915985 47.58065829171401, -122.38551735877991 47.5814398985005, -122.38706231117247 47.5819609632087))," +
766+
"((-122.38875210285185 47.580661910290814, -122.3882746696472 47.580661910290814, -122.3882746696472 47.58094415851252, -122.38875210285185 47.58094415851252, -122.38875210285185 47.580661910290814))," +
767+
"((-122.38595187664032 47.58192477832709, -122.38551199436188 47.58192477832709, -122.38551199436188 47.582203401270355, -122.38595187664032 47.582203401270355, -122.38595187664032 47.58192477832709))" +
768+
")")
769+
Geometry concaveHull = geometry.concaveHullOfPolygons(2.56)
770+
assertNotNull(concaveHull)
771+
assertEquals("Polygon", concaveHull.getGeometryType())
772+
}
773+
763774
@Test void covers() {
764775

765776
Polygon polygon1 = new Polygon([[

0 commit comments

Comments
 (0)