[geos-commits] [SCM] GEOS branch master updated. 2e4a7562f31f3663e0488044d0550da077ad66d9
git at osgeo.org
git at osgeo.org
Mon Aug 24 20:05:19 PDT 2020
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 2e4a7562f31f3663e0488044d0550da077ad66d9 (commit)
via 97c3e7778d3e0be6dfa849462e8308ddf278a726 (commit)
from 87ce4c1a06460d82fa97fb1c7736434015928ac5 (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 2e4a7562f31f3663e0488044d0550da077ad66d9
Merge: 97c3e77 87ce4c1
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Mon Aug 24 20:05:12 2020 -0700
Merge branch 'master' of https://git.osgeo.org/gitea/geos/geos
diff --cc capi/geos_ts_c.cpp
index 00a5cd7,361d634..7557459
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@@ -63,9 -63,9 +63,11 @@@
#include <geos/operation/distance/IndexedFacetDistance.h>
#include <geos/operation/linemerge/LineMerger.h>
#include <geos/operation/overlay/OverlayOp.h>
+ #include <geos/operation/overlayng/OverlayNG.h>
+ #include <geos/operation/overlayng/OverlayNGSnapIfNeeded.h>
#include <geos/operation/overlay/snap/GeometrySnapper.h>
+#include <geos/operation/overlayng/PrecisionReducer.h>
+#include <geos/operation/overlayng/OverlayNG.h>
#include <geos/operation/intersection/Rectangle.h>
#include <geos/operation/intersection/RectangleIntersection.h>
#include <geos/operation/polygonize/Polygonizer.h>
commit 97c3e7778d3e0be6dfa849462e8308ddf278a726
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Mon Aug 24 20:05:03 2020 -0700
When called without options, use OverlayNG for CAPI GEOSGeom_setPrecision
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 519da23..00a5cd7 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -64,6 +64,8 @@
#include <geos/operation/linemerge/LineMerger.h>
#include <geos/operation/overlay/OverlayOp.h>
#include <geos/operation/overlay/snap/GeometrySnapper.h>
+#include <geos/operation/overlayng/PrecisionReducer.h>
+#include <geos/operation/overlayng/OverlayNG.h>
#include <geos/operation/intersection/Rectangle.h>
#include <geos/operation/intersection/RectangleIntersection.h>
#include <geos/operation/polygonize/Polygonizer.h>
@@ -2336,15 +2338,23 @@ extern "C" {
else {
newpm.reset(new PrecisionModel());
}
+ Geometry* ret;
GeometryFactory::Ptr gf =
GeometryFactory::create(newpm.get(), g->getSRID());
- Geometry* ret;
if(gridSize != 0 && cursize != gridSize) {
// We need to snap the geometry
- GeometryPrecisionReducer reducer(*gf);
- reducer.setPointwise(flags & GEOS_PREC_NO_TOPO);
- reducer.setRemoveCollapsedComponents(!(flags & GEOS_PREC_KEEP_COLLAPSED));
- ret = reducer.reduce(*g).release();
+ if (flags) {
+ GeometryPrecisionReducer reducer(*gf);
+ reducer.setPointwise(flags & GEOS_PREC_NO_TOPO);
+ reducer.setRemoveCollapsedComponents(!(flags & GEOS_PREC_KEEP_COLLAPSED));
+ ret = reducer.reduce(*g).release();
+ }
+ else {
+ // OverlayNG reducer preserves topology and drops collapsed elements
+ // All it really is, is a call to OverlayNG::geomunion()
+ auto reducedGeom = geos::operation::overlayng::PrecisionReducer::reducePrecision(g, newpm.get());
+ ret = reducedGeom.release();
+ }
}
else {
// No need or willing to snap, just change the factory
diff --git a/include/geos/operation/overlayng/OverlayNG.h b/include/geos/operation/overlayng/OverlayNG.h
index aa88b12..d25a6f0 100644
--- a/include/geos/operation/overlayng/OverlayNG.h
+++ b/include/geos/operation/overlayng/OverlayNG.h
@@ -133,6 +133,23 @@ public:
* with a defined precision model.
* The noding strategy is determined by the precision model.
*/
+ OverlayNG(const geom::Geometry* geom0, const geom::Geometry* geom1, const geom::GeometryFactory* p_geomFact, int p_opCode)
+ : pm(p_geomFact->getPrecisionModel())
+ , inputGeom(geom0, geom1)
+ , geomFact(p_geomFact)
+ , opCode(p_opCode)
+ , noder(nullptr)
+ , isOptimized(true)
+ , isOutputEdges(false)
+ , isOutputResultEdges(false)
+ , isOutputNodedEdges(false)
+ {}
+
+ /**
+ * Creates an overlay operation on the given geometries,
+ * with a defined precision model.
+ * The noding strategy is determined by the precision model.
+ */
OverlayNG(const geom::Geometry* geom0, const geom::Geometry* geom1, const geom::PrecisionModel* p_pm, int p_opCode)
: pm(p_pm)
, inputGeom(geom0, geom1)
diff --git a/src/geom/LineString.cpp b/src/geom/LineString.cpp
index dc88966..dbd5ab0 100644
--- a/src/geom/LineString.cpp
+++ b/src/geom/LineString.cpp
@@ -324,7 +324,8 @@ LineString::normalizeClosed()
CoordinateSequence::scroll(uniqueCoordinates.get(), minCoordinate);
uniqueCoordinates->add(uniqueCoordinates->getAt(0));
- if(algorithm::Orientation::isCCW(uniqueCoordinates.get())) {
+
+ if(uniqueCoordinates->size() >= 4 && algorithm::Orientation::isCCW(uniqueCoordinates.get())) {
CoordinateSequence::reverse(uniqueCoordinates.get());
}
points = uniqueCoordinates.get()->clone();
diff --git a/src/operation/overlayng/OverlayNG.cpp b/src/operation/overlayng/OverlayNG.cpp
index dbcae1b..096f07e 100644
--- a/src/operation/overlayng/OverlayNG.cpp
+++ b/src/operation/overlayng/OverlayNG.cpp
@@ -101,7 +101,7 @@ std::unique_ptr<Geometry>
OverlayNG::overlay(const Geometry* geom0, const Geometry* geom1,
int opCode, noding::Noder* noder)
{
- OverlayNG ov(geom0, geom1, nullptr, opCode);
+ OverlayNG ov(geom0, geom1, static_cast<PrecisionModel*>(nullptr), opCode);
ov.setNoder(noder);
return ov.getResult();
}
diff --git a/src/operation/overlayng/PrecisionReducer.cpp b/src/operation/overlayng/PrecisionReducer.cpp
index 94bd2bc..811cbb7 100644
--- a/src/operation/overlayng/PrecisionReducer.cpp
+++ b/src/operation/overlayng/PrecisionReducer.cpp
@@ -26,8 +26,10 @@ namespace overlayng { // geos.operation.overlayng
std::unique_ptr<Geometry>
PrecisionReducer::reducePrecision(const Geometry* geom, const PrecisionModel* pm)
{
- std::unique_ptr<Geometry> reduced = OverlayNG::geomunion(geom, pm);
- return reduced;
+ auto gf = GeometryFactory::create(pm, geom->getSRID());
+ // OverlayNG(const geom::Geometry* geom0, const geom::Geometry* geom1, const geom::GeometryFactory* p_geomFact, int p_opCode)
+ OverlayNG ov(geom, nullptr, gf.get(), OverlayNG::UNION);
+ return ov.getResult();
}
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
index 44b2ad2..f4e29f3 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -25,6 +25,7 @@ EXTRA_DIST = \
tut/tut_runner.hpp \
tut/tut_xml_reporter.hpp \
util/NodingTestUtil.h \
+ capi/capi_test_utils.h \
CMakeLists.txt
diff --git a/tests/unit/capi/GEOSGeomFromWKBTest.cpp b/tests/unit/capi/GEOSGeomFromWKBTest.cpp
index 5d1b428..2f6638a 100644
--- a/tests/unit/capi/GEOSGeomFromWKBTest.cpp
+++ b/tests/unit/capi/GEOSGeomFromWKBTest.cpp
@@ -3,14 +3,8 @@
#include <tut/tut.hpp>
#include <utility.h> // wkb_hex_decoder
-// geos
-#include <geos_c.h>
-// std
-#include <string>
-#include <cstdarg>
-#include <cstdio>
-#include <cstdlib>
-#include <memory>
+
+#include "capi_test_utils.h"
namespace tut {
//
@@ -18,24 +12,11 @@ namespace tut {
//
// Common data used in test cases.
-struct test_capigeosgeomfromwkb_data {
+struct test_capigeosgeomfromwkb_data : public capitest::test_handlers {
GEOSGeometry* geom1_;
GEOSGeometry* geom2_;
GEOSWKTReader* reader_;
- static void
- notice(const char* fmt, ...)
- {
- std::fprintf(stdout, "NOTICE: ");
-
- va_list ap;
- va_start(ap, fmt);
- std::vfprintf(stdout, fmt, ap);
- va_end(ap);
-
- std::fprintf(stdout, "\n");
- }
-
test_capigeosgeomfromwkb_data()
: geom1_(nullptr), geom2_(nullptr), reader_(nullptr)
{
diff --git a/tests/unit/capi/GEOSGeom_createLineStringTest.cpp b/tests/unit/capi/GEOSGeom_createLineStringTest.cpp
index a9181bc..1061ce3 100644
--- a/tests/unit/capi/GEOSGeom_createLineStringTest.cpp
+++ b/tests/unit/capi/GEOSGeom_createLineStringTest.cpp
@@ -1,7 +1,4 @@
#include <tut/tut.hpp>
-// geos
-#include <geos_c.h>
-
#include "capi_test_utils.h"
namespace tut {
diff --git a/tests/unit/capi/GEOSGeom_setPrecisionTest.cpp b/tests/unit/capi/GEOSGeom_setPrecisionTest.cpp
index 68f3220..1f4998a 100644
--- a/tests/unit/capi/GEOSGeom_setPrecisionTest.cpp
+++ b/tests/unit/capi/GEOSGeom_setPrecisionTest.cpp
@@ -1,13 +1,6 @@
-//
-// Test Suite for C-API GEOSGeom_setPrecision_r
-
#include <tut/tut.hpp>
-// geos
-#include <geos_c.h>
-// std
-#include <cstdarg>
-#include <cstdio>
-#include <cstdlib>
+
+#include "capi_test_utils.h"
namespace tut {
//
@@ -15,25 +8,13 @@ namespace tut {
//
// Common data used in test cases.
-struct test_capigeosgeomsetprecision_data {
+struct test_capigeosgeomsetprecision_data : public capitest::test_handlers {
+
GEOSWKTWriter* wktw_;
GEOSGeometry* geom1_;
GEOSGeometry* geom2_;
GEOSGeometry* geom3_;
- static void
- notice(const char* fmt, ...)
- {
- std::fprintf(stdout, "NOTICE: ");
-
- va_list ap;
- va_start(ap, fmt);
- std::vfprintf(stdout, fmt, ap);
- va_end(ap);
-
- std::fprintf(stdout, "\n");
- }
-
GEOSGeometry*
fromWKT(const char* wkt)
{
@@ -69,9 +50,7 @@ struct test_capigeosgeomsetprecision_data {
}
GEOSWKTWriter_destroy(wktw_);
- geom1_ = nullptr;
- geom2_ = nullptr;
- geom3_ = nullptr;
+ geom1_ = geom2_ = geom3_ = nullptr;
finishGEOS();
}
@@ -92,14 +71,12 @@ void object::test<1>
()
{
geom1_ = fromWKT("POLYGON EMPTY");
- ensure(geom1_ != 0);
- double scale = GEOSGeom_getPrecision(geom1_);
- ensure_equals(scale, 0.0);
+ ensure_equals(GEOSGeom_getPrecision(geom1_), 0.0);
+
geom3_ = GEOSGeom_setPrecision(geom1_, 2.0, 0);
ensure(geom3_ != 0);
- ensure_equals(toWKT(geom3_), std::string("POLYGON EMPTY"));
- scale = GEOSGeom_getPrecision(geom3_);
- ensure_equals(scale, 2.0);
+ ensure(capi_geometry_same(geom3_, "POLYGON EMPTY"));
+ ensure_equals(GEOSGeom_getPrecision(geom3_), 2.0);
}
template<>
@@ -108,10 +85,9 @@ void object::test<2>
()
{
geom1_ = fromWKT("LINESTRING(-3 6, 9 1)");
- ensure(geom1_ != 0);
geom3_ = GEOSGeom_setPrecision(geom1_, 2.0, 0);
ensure(geom3_ != 0);
- ensure_equals(toWKT(geom3_), std::string("LINESTRING (-2 6, 10 2)"));
+ ensure(capi_geometry_same(geom3_, "LINESTRING (-2 6, 10 2)"));
}
// See effects of precision reduction on intersection operation
@@ -121,12 +97,11 @@ void object::test<3>
()
{
geom1_ = fromWKT("LINESTRING(2 10, 4 30)");
- ensure(geom1_ != 0);
geom2_ = fromWKT("LINESTRING(4 10, 2 30)");
- ensure(geom2_ != 0);
+
geom3_ = GEOSIntersection(geom1_, geom2_);
ensure(geom3_ != 0);
- ensure_equals(toWKT(geom3_), std::string("POINT (3 20)"));
+ ensure(capi_geometry_same(geom3_, "POINT (3 20)"));
GEOSGeometry* g;
@@ -142,7 +117,7 @@ void object::test<3>
GEOSGeom_destroy(geom3_);
geom3_ = GEOSIntersection(geom1_, geom2_);
ensure(geom3_ != 0);
- ensure_equals(toWKT(geom3_), std::string("POINT (4 20)"));
+ ensure(capi_geometry_same(geom3_, "POINT (4 20)"));
// One input with precision grid of 0.5, the other of 2.0
g = GEOSGeom_setPrecision(geom1_, 0.5, 0);
@@ -152,11 +127,10 @@ void object::test<3>
GEOSGeom_destroy(geom3_);
geom3_ = GEOSIntersection(geom1_, geom2_);
ensure(geom3_ != 0);
- ensure_equals(toWKT(geom3_), std::string("POINT (3 20)"));
- double scale = GEOSGeom_getPrecision(geom1_);
- ensure_equals(scale, 0.5);
- scale = GEOSGeom_getPrecision(geom2_);
- ensure_equals(scale, 2.0);
+ ensure(capi_geometry_same(geom3_, "POINT (3 20)"));
+
+ ensure_equals(GEOSGeom_getPrecision(geom1_), 0.5);
+ ensure_equals(GEOSGeom_getPrecision(geom2_), 2.0);
}
// Retain (or not) topology
@@ -166,15 +140,14 @@ void object::test<4>
()
{
geom1_ = fromWKT("POLYGON((10 10,20 10,16 15,20 20, 10 20, 14 15, 10 10))");
- ensure(geom1_ != 0);
+
geom2_ = GEOSGeom_setPrecision(geom1_, 5.0, 0);
- ensure_equals(toWKT(geom2_), std::string(
- "MULTIPOLYGON (((10 10, 15 15, 20 10, 10 10)), ((15 15, 10 20, 20 20, 15 15)))"
- ));
+ ensure(capi_geometry_same(geom2_,
+ "MULTIPOLYGON (((10 10, 15 15, 20 10, 10 10)), ((15 15, 10 20, 20 20, 15 15)))"));
+
geom3_ = GEOSGeom_setPrecision(geom1_, 5.0, GEOS_PREC_NO_TOPO);
- ensure_equals(toWKT(geom3_), std::string(
- "POLYGON ((10 10, 20 10, 15 15, 20 20, 10 20, 15 15, 10 10))"
- ));
+ ensure(capi_geometry_same(geom3_,
+ "POLYGON ((10 10, 20 10, 15 15, 20 20, 10 20, 15 15, 10 10))"));
}
// Retain (or not) collapsed elements
@@ -184,15 +157,12 @@ void object::test<5>
()
{
geom1_ = fromWKT("LINESTRING(1 0, 2 0)");
- ensure(geom1_ != 0);
+
geom2_ = GEOSGeom_setPrecision(geom1_, 5.0, 0);
- ensure_equals(toWKT(geom2_), std::string(
- "LINESTRING EMPTY"
- ));
+ ensure(capi_geometry_same(geom2_, "LINESTRING EMPTY"));
+
geom3_ = GEOSGeom_setPrecision(geom1_, 5.0, GEOS_PREC_KEEP_COLLAPSED);
- ensure_equals(toWKT(geom3_), std::string(
- "LINESTRING (0 0, 0 0)"
- ));
+ ensure_equals(toWKT(geom3_), "LINESTRING (0 0, 0 0)");
}
} // namespace tut
diff --git a/tests/unit/capi/capi_test_utils.h b/tests/unit/capi/capi_test_utils.h
index 3a4a6e5..a725c53 100644
--- a/tests/unit/capi/capi_test_utils.h
+++ b/tests/unit/capi/capi_test_utils.h
@@ -1,5 +1,5 @@
-#ifndef GEOS_CAPI_TEST_UTILS_H
-#define GEOS_CAPI_TEST_UTILS_H
+
+#pragma once
#include <geos_c.h>
@@ -9,8 +9,6 @@
#include <cstring>
-
-
namespace capitest {
struct test_handlers {
@@ -26,6 +24,30 @@ namespace capitest {
std::fprintf(stdout, "\n");
}
+ bool
+ capi_geometry_same(GEOSGeometry* g1, GEOSGeometry* g2, double tolerance)
+ {
+ GEOSNormalize(g1);
+ GEOSNormalize(g2);
+ return GEOSEqualsExact(g1, g2, tolerance);
+ }
+
+ bool
+ capi_geometry_same(GEOSGeometry* g1, GEOSGeometry* g2)
+ {
+ return capi_geometry_same(g1, g2, 1e-12);
+ }
+
+ bool
+ capi_geometry_same(GEOSGeometry* g1, const char* g2str)
+ {
+ GEOSGeometry* g2 = GEOSGeomFromWKT(g2str);
+ tut::ensure(g2 != 0);
+ bool rslt = capi_geometry_same(g1, g2);
+ GEOSGeom_destroy(g2);
+ return rslt;
+ }
+
test_handlers()
{
initGEOS(notice, notice);
@@ -39,4 +61,3 @@ namespace capitest {
}
-#endif
-----------------------------------------------------------------------
Summary of changes:
capi/geos_ts_c.cpp | 20 ++++--
include/geos/operation/overlayng/OverlayNG.h | 17 +++++
src/geom/LineString.cpp | 3 +-
src/operation/overlayng/OverlayNG.cpp | 2 +-
src/operation/overlayng/PrecisionReducer.cpp | 6 +-
tests/unit/Makefile.am | 1 +
tests/unit/capi/GEOSGeomFromWKBTest.cpp | 25 +------
tests/unit/capi/GEOSGeom_createLineStringTest.cpp | 3 -
tests/unit/capi/GEOSGeom_setPrecisionTest.cpp | 84 ++++++++---------------
tests/unit/capi/capi_test_utils.h | 31 +++++++--
10 files changed, 96 insertions(+), 96 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list