Skip to content

Commit c19b9a9

Browse files
authored
Merge pull request #62 from geoscript/GSG-58.LargestEmptyCircle
Add largest empty circle method to Geometry
2 parents cbbcc49 + 99d99c1 commit c19b9a9

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package geoscript.geom
22

3+
import org.locationtech.jts.algorithm.construct.LargestEmptyCircle
34
import org.locationtech.jts.algorithm.construct.MaximumInscribedCircle
45
import org.locationtech.jts.geom.Geometry as JtsGeometry
56
import org.locationtech.jts.geom.GeometryFactory
@@ -525,6 +526,18 @@ class Geometry {
525526
Geometry.wrap(centerPoint.buffer(radiusLineString.getLength()))
526527
}
527528

529+
/**
530+
* Get the largest empty circle for this Geometry
531+
* @param tolerance The tolerance which defaults to 1.0
532+
* @return The largest empty circle
533+
*/
534+
Geometry getLargestEmptyCircle(double tolerance = 1.0) {
535+
LargestEmptyCircle algorithm = new LargestEmptyCircle(g, tolerance)
536+
def radiusLineString = algorithm.getRadiusLine()
537+
def centerPoint = radiusLineString.getStartPoint()
538+
Geometry.wrap(centerPoint.buffer(radiusLineString.getLength()))
539+
}
540+
528541
/**
529542
* Get Delaunay Triangle Diagram for this Geometry
530543
* @return A Delaunay Triangle Diagram Geometry

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,18 @@ class GeometryTestCase {
519519
assertTrue(circle instanceof Polygon)
520520
}
521521

522+
@Test void getLargestEmptyCircle() {
523+
Geometry g = Geometry.fromWKT("POLYGON ((-122.38855361938475 47.5805786829606, -122.38636493682861 47.5783206388176, " +
524+
"-122.38700866699219 47.5750491969984, -122.38177299499512 47.57502024527343, " +
525+
"-122.38481998443604 47.5780600889959, -122.38151550292969 47.5805786829606, " +
526+
"-122.38855361938475 47.5805786829606))")
527+
Geometry circle = g.getLargestEmptyCircle(1.0)
528+
assertNotNull circle
529+
assertTrue circle.isValid()
530+
assertFalse circle.isEmpty()
531+
assertTrue(circle instanceof Polygon)
532+
}
533+
522534
/*@Test void createFromText() {
523535
Geometry g = Geometry.createFromText("B")
524536
assertEquals "Polygon", g.geometryType

0 commit comments

Comments
 (0)