Skip to content

Commit cbbcc49

Browse files
authored
Merge pull request #61 from geoscript/GSG-59
Add maximum inscribed circle method to Geometry
2 parents d5568db + 9236037 commit cbbcc49

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
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.MaximumInscribedCircle
34
import org.locationtech.jts.geom.Geometry as JtsGeometry
45
import org.locationtech.jts.geom.GeometryFactory
56
import org.locationtech.jts.geom.Coordinate
@@ -512,6 +513,18 @@ class Geometry {
512513
Geometry.wrap(oct.toGeometry(factory))
513514
}
514515

516+
/**
517+
* Get the maximum inscribed circle for this Geometry
518+
* @param tolerance The tolerance which defaults to 1.0
519+
* @return The maximum inscribed circle
520+
*/
521+
Geometry getMaximumInscribedCircle(double tolerance = 1.0) {
522+
MaximumInscribedCircle algorithm = new MaximumInscribedCircle(g, tolerance)
523+
def radiusLineString = algorithm.getRadiusLine()
524+
def centerPoint = radiusLineString.getStartPoint()
525+
Geometry.wrap(centerPoint.buffer(radiusLineString.getLength()))
526+
}
527+
515528
/**
516529
* Get Delaunay Triangle Diagram for this Geometry
517530
* @return A Delaunay Triangle Diagram Geometry

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,19 @@ class GeometryTestCase {
506506
assertTrue octalEnvelope.isValid()
507507
assertFalse octalEnvelope.isEmpty()
508508
}
509-
509+
510+
@Test void getMaximumInscribedCircle() {
511+
Geometry g = Geometry.fromWKT("POLYGON ((-122.38855361938475 47.5805786829606, -122.38636493682861 47.5783206388176, " +
512+
"-122.38700866699219 47.5750491969984, -122.38177299499512 47.57502024527343, " +
513+
"-122.38481998443604 47.5780600889959, -122.38151550292969 47.5805786829606, " +
514+
"-122.38855361938475 47.5805786829606))")
515+
Geometry circle = g.getMaximumInscribedCircle(1.0)
516+
assertNotNull circle
517+
assertTrue circle.isValid()
518+
assertFalse circle.isEmpty()
519+
assertTrue(circle instanceof Polygon)
520+
}
521+
510522
/*@Test void createFromText() {
511523
Geometry g = Geometry.createFromText("B")
512524
assertEquals "Polygon", g.geometryType

0 commit comments

Comments
 (0)