[geos-commits] [SCM] GEOS branch master updated. 518105d6da791a16d05629e2073be19433d93ddf

git at osgeo.org git at osgeo.org
Thu Jan 7 13:20:27 PST 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, master has been updated
       via  518105d6da791a16d05629e2073be19433d93ddf (commit)
      from  cb6e27944bf53f683797f314630862d9ee5fa73b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 518105d6da791a16d05629e2073be19433d93ddf
Author: Martin Davis <mtnclimb at gmail.com>
Date:   Thu Jan 7 13:20:22 2021 -0800

    Add geosop distance and nearestPoints operations

diff --git a/util/geosop/GeomFunction.cpp b/util/geosop/GeomFunction.cpp
index eb75925..7ea8ed7 100644
--- a/util/geosop/GeomFunction.cpp
+++ b/util/geosop/GeomFunction.cpp
@@ -23,6 +23,7 @@
 #include <geos/geom/GeometryFactory.h>
 #include <geos/geom/prep/PreparedGeometry.h>
 #include <geos/geom/prep/PreparedGeometryFactory.h>
+#include <geos/operation/distance/DistanceOp.h>
 #include <geos/operation/relate/RelateOp.h>
 #include <geos/operation/valid/MakeValid.h>
 #include <geos/operation/overlayng/OverlayNG.h>
@@ -77,31 +78,50 @@ GeomFunction::init()
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
             return new Result( geom->covers( geomB.get() ) );
         });
+
+    add("distance", "computes distance between geometry A and B", 2, 0,
+        [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
+            return new Result( geom->distance( geomB.get() ) );
+        });
+
      add("envelope",
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
             return new Result( geom->getCentroid() );
         });
+
     add("interiorPoint",
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
             return new Result( geom->getInteriorPoint() );
         });
+
     add("intersects", "tests if geometry A and B intersect", 2, 0,
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
             return new Result( geom->intersects( geomB.get() ) );
         });
+
     add("isValid", "tests if geometry A is valid", 1, 0,
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
             return new Result( geom->isValid() );
         });
+
     add("length",
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
             return new Result( geom->getLength() );
         });
+
     add("makeValid",
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
             return new Result( geos::operation::valid::MakeValid().build( geom.get() ) );
         });
 
+    add("nearestPoints", "computes nearest points of geometry A and B", 2, 0,
+        [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
+            std::unique_ptr<CoordinateSequence> cs = geos::operation::distance::DistanceOp::nearestPoints(geom.get(), geomB.get());
+            auto factory = geom->getFactory();
+            auto res = factory->createLineString( std::move(cs) );
+            return new Result( std::move(res) );
+        });
+
     add("polygonize",
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
             geos::operation::polygonize::Polygonizer p;
@@ -147,7 +167,7 @@ GeomFunction::init()
             }
             return new Result( prepGeomCache->covers( geomB.get() ) );
         });
-    add("intersectsPrep", "tests if geometry A intersects geometry B using PreparedGeometry", 2, 0,
+    add("intersectsPrep", "tests if geometry A intersects B using PreparedGeometry", 2, 0,
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
             if (cacheKey == nullptr || cacheKey != geom.get()) {
                 auto pg = std::unique_ptr<const PreparedGeometry>(
@@ -158,6 +178,30 @@ GeomFunction::init()
             return new Result( prepGeomCache->intersects( geomB.get() ) );
         });
 
+    add("distancePrep", "computes distance between geometry A and B using PreparedGeometry", 2, 0,
+        [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
+            if (cacheKey == nullptr || cacheKey != geom.get()) {
+                auto pg = std::unique_ptr<const PreparedGeometry>(
+                    PreparedGeometryFactory::prepare( geom.get()) );
+                prepGeomCache = std::move( pg );
+                cacheKey = geom.get();
+            }
+            return new Result( prepGeomCache->distance( geomB.get() ) );
+        });
+    add("nearestPointsPrep", "computes nearest points of geometry A and B using PreparedGeometry", 2, 0,
+        [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
+            if (cacheKey == nullptr || cacheKey != geom.get()) {
+                auto pg = std::unique_ptr<const PreparedGeometry>(
+                    PreparedGeometryFactory::prepare( geom.get()) );
+                prepGeomCache = std::move( pg );
+                cacheKey = geom.get();
+            }
+            auto cs = prepGeomCache->nearestPoints( geomB.get() );
+            auto factory = geom->getFactory();
+            auto res = factory->createLineString( std::move(cs) );
+            return new Result( std::move(res) );
+        });
+
 
     add("reducePrecision", "reduces precision of geometry to a precision scale factor", 1, 1,
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {

-----------------------------------------------------------------------

Summary of changes:
 util/geosop/GeomFunction.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list