Skip to content

Commit e473443

Browse files
committed
Add concave hull method to Geometry.
1 parent 726eeb1 commit e473443

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package geoscript.geom
22

33
import org.locationtech.jts.algorithm.construct.LargestEmptyCircle
44
import org.locationtech.jts.algorithm.construct.MaximumInscribedCircle
5+
import org.locationtech.jts.algorithm.hull.ConcaveHull
56
import org.locationtech.jts.geom.Geometry as JtsGeometry
67
import org.locationtech.jts.geom.GeometryFactory
78
import org.locationtech.jts.geom.Coordinate
@@ -134,6 +135,15 @@ class Geometry {
134135
wrap(g.convexHull())
135136
}
136137

138+
/**
139+
* Calculate the concave hull
140+
* @param maxLength The max length
141+
* @return A Geometry
142+
*/
143+
Geometry concaveHull(double maxLength = 0.0) {
144+
wrap(ConcaveHull.concaveHullByLength(g, maxLength))
145+
}
146+
137147
/**
138148
* Whether this Geometry is covered by the other Geometry
139149
* @param The other Geometry

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,30 @@ geometry:
737737
new Point(-90.7031, 34.016)
738738
)
739739
Geometry convexHull = geometry.convexHull
740-
assertEquals("POLYGON ((-90.7031 34.016, -111.796 42.553, -119.882 47.279, " +
741-
"-100.195 46.316, -90.7031 34.016))", convexHull.wkt)
740+
assertEquals("POLYGON ((-122.3876953125 47.58121554959838, -122.39078521728516 47.58167872046887, " +
741+
"-122.3876953125 47.5828366297174, -122.38657951354979 47.58451555263637, " +
742+
"-122.38494873046875 47.58301031389572, -122.38177299499512 47.5823155737249, " +
743+
"-122.38486289978027 47.5812734461813, -122.38649368286131 47.5772205307505, " +
744+
"-122.3876953125 47.58121554959838))", convexHull.wkt)
745+
}
746+
747+
@Test void concaveHull() {
748+
Geometry geometry = Geometry.fromWKT("MULTIPOINT (" +
749+
"(-122.38657951354979 47.58451555263637), "+
750+
"(-122.38649368286131 47.5772205307505), "+
751+
"(-122.39078521728516 47.58167872046887), "+
752+
"(-122.38177299499512 47.5823155737249), "+
753+
"(-122.3876953125 47.5828366297174), "+
754+
"(-122.38494873046875 47.58301031389572), "+
755+
"(-122.3876953125 47.58121554959838), "+
756+
"(-122.38486289978027 47.5812734461813)"+
757+
")")
758+
Geometry concaveHull = geometry.concaveHull()
759+
assertEquals("POLYGON ((-122.3876953125 47.58121554959838, -122.39078521728516 47.58167872046887, " +
760+
"-122.3876953125 47.5828366297174, -122.38657951354979 47.58451555263637, " +
761+
"-122.38494873046875 47.58301031389572, -122.38177299499512 47.5823155737249, " +
762+
"-122.38486289978027 47.5812734461813, -122.38649368286131 47.5772205307505, " +
763+
"-122.3876953125 47.58121554959838))", concaveHull.wkt)
742764
}
743765

744766
@Test void covers() {

0 commit comments

Comments
 (0)