[geos-commits] [SCM] GEOS branch master updated. 946a75daa4e48b392297e07f45ac0730e2c832e8

git at osgeo.org git at osgeo.org
Thu Jan 7 23:14:31 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  946a75daa4e48b392297e07f45ac0730e2c832e8 (commit)
      from  534eebc107a996b51376c25505649a273dbe96a6 (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 946a75daa4e48b392297e07f45ac0730e2c832e8
Author: Martin Davis <mtnclimb at gmail.com>
Date:   Thu Jan 7 23:14:25 2021 -0800

    Add geosop delaunay and voronoi ops

diff --git a/util/geosop/GeomFunction.cpp b/util/geosop/GeomFunction.cpp
index 1779e1b..05185b1 100644
--- a/util/geosop/GeomFunction.cpp
+++ b/util/geosop/GeomFunction.cpp
@@ -31,6 +31,8 @@
 #include <geos/operation/overlayng/OverlayNG.h>
 #include <geos/operation/polygonize/Polygonizer.h>
 #include <geos/precision/GeometryPrecisionReducer.h>
+#include <geos/triangulate/DelaunayTriangulationBuilder.h>
+#include <geos/triangulate/VoronoiDiagramBuilder.h>
 
 #include "GeomFunction.h"
 
@@ -142,20 +144,49 @@ GeomFunction::init()
             return new Result( std::move(res) );
         });
 
+    add("delaunay", "computes the Delaunay Triangulation of geometry A vertices", 1, 0,
+        [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
+            geos::triangulate::DelaunayTriangulationBuilder builder;
+            builder.setTolerance(0);
+            builder.setSites( *geom );
+
+            Geometry* out = builder.getTriangles(*(geom->getFactory())).release();
+
+            std::vector<std::unique_ptr<const Geometry>> geoms;
+            for(unsigned int i = 0; i < out->getNumGeometries(); i++) {
+                geoms.push_back( std::unique_ptr< const Geometry>( out->getGeometryN(i) ) );
+            }
+            return new Result( std::move(geoms) ) ;
+        });
+
+    add("voronoi", "computes the Voronoi Diagram of geometry A vertices", 1, 0,
+        [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
+            geos::triangulate::VoronoiDiagramBuilder builder;
+            builder.setTolerance(0);
+            builder.setSites( *geom );
+
+            Geometry* out = builder.getDiagram(*(geom->getFactory())).release();
+
+            std::vector<std::unique_ptr<const Geometry>> geoms;
+            for(unsigned int i = 0; i < out->getNumGeometries(); i++) {
+                geoms.push_back( std::unique_ptr< const Geometry>( out->getGeometryN(i) ) );
+            }
+            return new Result( std::move(geoms) ) ;
+        });
+
     add("polygonize",
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
             geos::operation::polygonize::Polygonizer p;
             p.add(geom.get());
 
             auto polys = p.getPolygons();
-            std::vector<geom::Geometry*>* geoms = new std::vector<geom::Geometry*>;
+            std::vector<std::unique_ptr<const Geometry>> geoms;
             for(unsigned int i = 0; i < polys.size(); i++) {
-                geoms->push_back(polys[i].release());
+                geoms.push_back( std::move(polys[i]) );
             }
-            auto factory = geom->getFactory();
-            Geometry * res = factory->createGeometryCollection(geoms);
-            return new Result( res) ;
+            return new Result( std::move(geoms) ) ;
         });
+
     add("reverse", "reverses geometry A", 1, 0,
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
             return new Result( geom->reverse() );
@@ -395,6 +426,12 @@ Result::Result(Geometry * val)
     typeCode = typeGeometry;
 }
 
+Result::Result( std::vector<std::unique_ptr<const Geometry>> val )
+{
+    valGeomList = std::move(val);
+    typeCode = typeGeomList;
+}
+
 Result::~Result()
 {
 }
@@ -404,6 +441,11 @@ Result::isGeometry() {
     return typeCode == typeGeometry;
 }
 
+bool
+Result::isGeometryList() {
+    return typeCode == typeGeomList;
+}
+
 std::string
 Result::toString() {
     std::stringstream converter;
@@ -427,6 +469,9 @@ Result::toString() {
         if (valGeom == nullptr)
             return "null";
         return valGeom->toString();
+
+    case typeGeomList:
+       return metadata();
     }
     return "Value for Unknonwn type";
 }
@@ -443,6 +488,9 @@ Result::metadata() {
         if (valGeom == nullptr)
             return "null";
         return valGeom->getGeometryType() + "( " + std::to_string( valGeom->getNumPoints() ) + " )";
+
+    case typeGeomList:
+        return "Geometry[" + std::to_string( valGeomList.size()) + "]";
     }
     return "Unknonwn type";
 }
diff --git a/util/geosop/GeomFunction.h b/util/geosop/GeomFunction.h
index 6d2708d..5d9938a 100644
--- a/util/geosop/GeomFunction.h
+++ b/util/geosop/GeomFunction.h
@@ -33,22 +33,25 @@ public:
     double valDouble;
     std::string valStr;
     std::unique_ptr<Geometry> valGeom;
+    std::vector<std::unique_ptr<const Geometry>> valGeomList;
 
     Result(bool val);
     Result(int val);
     Result(std::string val);
     Result(double val);
     Result(std::unique_ptr<Geometry> val);
+    Result(std::vector<std::unique_ptr<const Geometry>> val);
     Result(Geometry * val);
     ~Result();
 
     bool isGeometry();
+    bool isGeometryList();
     std::string metadata();
     std::string toString();
 
 private:
     enum {
-        typeBool = 1, typeInt, typeDouble, typeString, typeGeometry
+        typeBool = 1, typeInt, typeDouble, typeString, typeGeometry, typeGeomList
     } typeCode;
 };
 
diff --git a/util/geosop/GeosOp.cpp b/util/geosop/GeosOp.cpp
index 066b0ff..034312e 100644
--- a/util/geosop/GeosOp.cpp
+++ b/util/geosop/GeosOp.cpp
@@ -429,6 +429,9 @@ void GeosOp::output(Result* result) {
             outputGeometry( result->valGeom.get() );
         }
     }
+    else if (result->isGeometryList() ) {
+        outputGeometryList( result->valGeomList );
+    }
     else {
         // output as text/WKT
         std::cout << result->toString() << std::endl;
@@ -462,3 +465,9 @@ void GeosOp::outputGeometry(const Geometry * geom) {
         std::cout << writer.write(geom) << std::endl;
     }
 }
+
+void GeosOp::outputGeometryList(std::vector<std::unique_ptr<const Geometry>> & list) {
+    for (size_t i = 0; i < list.size(); i++) {
+        outputGeometry( list[i].get() );
+    }
+}
diff --git a/util/geosop/GeosOp.h b/util/geosop/GeosOp.h
index 66f7bfe..f38a754 100644
--- a/util/geosop/GeosOp.h
+++ b/util/geosop/GeosOp.h
@@ -79,6 +79,7 @@ private:
     void output(Result* result);
     void outputExplode(std::unique_ptr<Geometry>& geom);
     void outputGeometry( const Geometry* geom);
+    void outputGeometryList(std::vector<std::unique_ptr<const Geometry>> & val);
     void log(std::string s);
 };
 

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

Summary of changes:
 util/geosop/GeomFunction.cpp | 58 ++++++++++++++++++++++++++++++++++++++++----
 util/geosop/GeomFunction.h   |  5 +++-
 util/geosop/GeosOp.cpp       |  9 +++++++
 util/geosop/GeosOp.h         |  1 +
 4 files changed, 67 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list