File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
main/groovy/geoscript/geom
test/groovy/geoscript/geom Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 11package geoscript.geom
22
3+ import org.locationtech.jts.algorithm.construct.MaximumInscribedCircle
34import org.locationtech.jts.geom.Geometry as JtsGeometry
45import org.locationtech.jts.geom.GeometryFactory
56import 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments