From e5ff6058d3e7b96b189bf52bad80d1617bedc7f2 Mon Sep 17 00:00:00 2001 From: Jared Erickson Date: Wed, 5 Aug 2020 17:00:04 -0700 Subject: [PATCH] Add largest empty circle method to Geometry. --- doc/api/geom/geometry.rst | 7 ++++--- src/main/java/org/geoscript/js/geom/Geometry.java | 11 +++++++++++ .../org/geoscript/js/tests/geoscript/test_geom.js | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/doc/api/geom/geometry.rst b/doc/api/geom/geometry.rst index a1922f7..7974b24 100644 --- a/doc/api/geom/geometry.rst +++ b/doc/api/geom/geometry.rst @@ -274,9 +274,10 @@ Common Geometry Methods Tests if this geometry is within the other geometry. This is the inverse of :func:`contains`. +.. function:: Geometry.getLargestEmptyCircle + :arg config: :`Object` tolerance property defaults to 1.0 + :returns: :class:`geom.Geometry` - - - + Get the largest empty circle in this Geometry. diff --git a/src/main/java/org/geoscript/js/geom/Geometry.java b/src/main/java/org/geoscript/js/geom/Geometry.java index 35bb87e..1df9579 100644 --- a/src/main/java/org/geoscript/js/geom/Geometry.java +++ b/src/main/java/org/geoscript/js/geom/Geometry.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Objects; +import org.locationtech.jts.algorithm.construct.LargestEmptyCircle; import org.locationtech.jts.densify.Densifier; import org.geoscript.js.GeoObject; import org.geoscript.js.proj.Projection; @@ -359,6 +360,16 @@ public ScriptableObject createDelaunayTriangles(boolean isConforming) { return triangles; } + @JSFunction + public Geometry getLargestEmptyCircle(NativeObject config) { + double tolerance = getDouble(config.getOrDefault("tolerance", 1.0)); + LargestEmptyCircle algorithm = new LargestEmptyCircle(getGeometry(), tolerance); + return (Geometry) GeometryWrapper.wrap( + getParentScope(), + algorithm.getCenter().buffer(algorithm.getRadiusLine().getLength()) + ); + } + @JSFunction public String getGeometryType() { return geometry.getGeometryType(); diff --git a/src/test/resources/org/geoscript/js/tests/geoscript/test_geom.js b/src/test/resources/org/geoscript/js/tests/geoscript/test_geom.js index 769a387..34ed88e 100644 --- a/src/test/resources/org/geoscript/js/tests/geoscript/test_geom.js +++ b/src/test/resources/org/geoscript/js/tests/geoscript/test_geom.js @@ -176,6 +176,20 @@ exports["test: create random points"] = function() { } +exports["test: largest empty circle"] = function() { + + var geom = new GEOM.Polygon([[ + [-122.38855361938475, 47.5805786829606], [-122.38636493682861, 47.5783206388176], + [-122.38700866699219, 47.5750491969984], [-122.38177299499512, 47.57502024527343], + [-122.38481998443604, 47.5780600889959], [-122.38151550292969, 47.5805786829606], + [-122.38855361938475, 47.5805786829606] + ]]); + ASSERT.ok(geom instanceof GEOM.Polygon); + var circle = geom.getLargestEmptyCircle({tolerance: 1.0}); + ASSERT.ok(circle instanceof GEOM.Polygon); + +} + exports["test: create conforming delaunay triangles"] = function() { var geom = GEOM.Point([1,1]).buffer(50)