[geos-commits] [SCM] GEOS branch main-relate-ng updated. 2c9887a0df473f999f8d8fb89e56077d25bf7d50
git at osgeo.org
git at osgeo.org
Wed Jul 3 13:18:19 PDT 2024
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, main-relate-ng has been updated
via 2c9887a0df473f999f8d8fb89e56077d25bf7d50 (commit)
from 3c040699dca4eb10c711c09f279cc93235528a4e (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 2c9887a0df473f999f8d8fb89e56077d25bf7d50
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Wed Jul 3 13:14:41 2024 -0700
Add LinearBoundaryTest and fix LinearBoundary cardinality counter
diff --git a/include/geos/operation/relateng/LineStringExtracter.h b/include/geos/operation/relateng/LineStringExtracter.h
new file mode 100644
index 000000000..fc7298f88
--- /dev/null
+++ b/include/geos/operation/relateng/LineStringExtracter.h
@@ -0,0 +1,77 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (c) 2024 Martin Davis
+ * Copyright (C) 2024 Paul Ramsey <pramsey at cleverelephant.ca>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+#pragma once
+
+#include <geos/geom/GeometryFilter.h>
+#include <geos/export.h>
+
+#include <memory>
+#include <vector>
+
+// Forward declarations
+namespace geos {
+namespace geom {
+ class LineString;
+ class Geometry;
+}
+}
+
+
+using geos::geom::LineString;
+using geos::geom::Geometry;
+using geos::geom::GeometryFilter;
+
+
+namespace geos { // geos.
+namespace operation { // geos.operation
+namespace relateng { // geos.operation.relateng
+
+
+class GEOS_DLL LineStringExtracter : public GeometryFilter {
+
+private:
+
+ std::vector<const LineString*>& comps;
+
+
+public:
+
+ LineStringExtracter(std::vector<const LineString*>& p_comps)
+ : comps(p_comps)
+ {}
+
+ void filter_ro(const geom::Geometry* geom) override;
+
+ static void getLines(const Geometry* geom, std::vector<const LineString*>& lines);
+
+ static std::vector<const LineString*> getLines(const Geometry* geom);
+
+ /**
+ * Extracts the {@link LineString} elements from a single {@link Geometry}
+ * and returns them as either a {@link LineString} or {@link MultiLineString}.
+ *
+ * @param geom the geometry from which to extract
+ * @return a linear geometry
+ */
+ // static std::unique_ptr<Geometry> getGeometry(const Geometry* geom);
+
+};
+
+
+} // namespace geos.operation.relateng
+} // namespace geos.operation
+} // namespace geos
+
diff --git a/src/operation/relateng/LineStringExtracter.cpp b/src/operation/relateng/LineStringExtracter.cpp
new file mode 100644
index 000000000..b1c229cba
--- /dev/null
+++ b/src/operation/relateng/LineStringExtracter.cpp
@@ -0,0 +1,87 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (c) 2024 Martin Davis
+ * Copyright (C) 2024 Paul Ramsey <pramsey at cleverelephant.ca>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+#include <geos/operation/relateng/LineStringExtracter.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/GeometryFactory.h>
+#include <geos/geom/LineString.h>
+#include <geos/constants.h>
+#include <sstream>
+
+
+using geos::geom::Geometry;
+using geos::geom::GeometryFactory;
+using geos::geom::LineString;
+
+
+namespace geos { // geos
+namespace operation { // geos.operation
+namespace relateng { // geos.operation.relateng
+
+
+/* public static */
+void
+LineStringExtracter::getLines(const Geometry* geom, std::vector<const LineString*>& lines)
+{
+ if (geom->getGeometryTypeId() == geom::GEOS_LINESTRING) {
+ lines.push_back(static_cast<const LineString*>(geom));
+ }
+ else if (geom->isCollection()) {
+ LineStringExtracter lse(lines);
+ geom->apply_ro(&lse);
+ }
+ // skip non-LineString elemental geometries
+
+ return;
+}
+
+
+/* public static */
+std::vector<const LineString*>
+LineStringExtracter::getLines(const Geometry* geom)
+{
+ std::vector<const LineString*> lines;
+ getLines(geom, lines);
+ return lines;
+}
+
+
+/* public static */
+// std::unique_ptr<Geometry>
+// LineStringExtracter::getGeometry(const Geometry* geom)
+// {
+// std::vector<const LineString*> lines;
+// getLines(geom, lines);
+// return geom->getFactory()->buildGeometry(lines);
+// }
+
+
+/* public */
+void
+LineStringExtracter::filter_ro(const Geometry* geom)
+{
+ if (geom->getGeometryTypeId() == geom::GEOS_LINESTRING)
+ comps.push_back(static_cast<const LineString*>(geom));
+}
+
+
+
+} // namespace geos.operation.overlayng
+} // namespace geos.operation
+} // namespace geos
+
+
+
+
diff --git a/src/operation/relateng/LinearBoundary.cpp b/src/operation/relateng/LinearBoundary.cpp
index 84caee1c1..5b4dfbae7 100644
--- a/src/operation/relateng/LinearBoundary.cpp
+++ b/src/operation/relateng/LinearBoundary.cpp
@@ -100,9 +100,10 @@ LinearBoundary::addEndpoint(const CoordinateXY *p, Coordinate::ConstIntMap& vert
if (it != vertexDegree.end()) {
dim = it->second;
}
- dim++;
- std::pair<const CoordinateXY*, int> entry(p, dim);
- vertexDegree.insert(entry);
+ // dim++;
+ // std::pair<const CoordinateXY*, int> entry(p, dim);
+ // vertexDegree.insert(entry);
+ vertexDegree[p] = dim + 1;
}
diff --git a/tests/unit/operation/relateng/LinearBoundaryTest.cpp b/tests/unit/operation/relateng/LinearBoundaryTest.cpp
new file mode 100644
index 000000000..620c3bcb9
--- /dev/null
+++ b/tests/unit/operation/relateng/LinearBoundaryTest.cpp
@@ -0,0 +1,147 @@
+//
+// Test Suite for geos::operation::relateng::LinearBoundary class.
+
+#include <tut/tut.hpp>
+#include <utility.h>
+
+// geos
+#include <geos/algorithm/BoundaryNodeRule.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/Location.h>
+#include <geos/io/WKTReader.h>
+//#include <geos/io/WKTWriter.h>
+#include <geos/operation/relateng/LinearBoundary.h>
+#include <geos/operation/relateng/LineStringExtracter.h>
+
+// std
+#include <memory>
+
+using namespace geos::geom;
+using namespace geos::operation::relateng;
+using geos::algorithm::BoundaryNodeRule;
+using geos::io::WKTReader;
+// using geos::io::WKTWriter;
+
+namespace tut {
+//
+// Test Group
+//
+
+// Common data used by all tests
+struct test_linearboundary_data {
+
+ WKTReader r;
+ // WKTWriter w;
+
+ void
+ checkLinearBoundary(const std::string& wkt, const BoundaryNodeRule& bnr, const std::string& wktBdyExpected)
+ {
+ std::unique_ptr<Geometry> geom = r.read(wkt);
+ auto lines = extractLines(*geom);
+ LinearBoundary lb(lines, bnr);
+ bool hasBoundaryExpected = wktBdyExpected.length() == 0 ? false : true;
+ ensure_equals("hasBoundaryExpected == lb.hasBoundary", hasBoundaryExpected, lb.hasBoundary());
+
+ checkBoundaryPoints(lb, *geom, wktBdyExpected);
+ }
+
+ void
+ checkBoundaryPoints(LinearBoundary& lb, Geometry& geom, const std::string& wktBdyExpected)
+ {
+ std::set<CoordinateXY> bdySet;
+ extractPoints(wktBdyExpected, bdySet);
+
+ for (const CoordinateXY& p : bdySet) {
+ ensure("checkBoundaryPoints1", lb.isBoundary(&p));
+ }
+
+ auto allPts = geom.getCoordinates();
+ for (std::size_t i = 0; i < allPts->size(); i++) {
+ CoordinateXY p;
+ allPts->getAt(i, p);
+ if (bdySet.find(p) == bdySet.end()) { // p not in bdySet
+ ensure("checkBoundaryPoints2", !lb.isBoundary(&p));
+ }
+ }
+ }
+
+ void
+ extractPoints(const std::string& wkt, std::set<CoordinateXY>& ptSet)
+ {
+ if (wkt.length() == 0) return;
+ auto geom = r.read(wkt);
+ auto pts = geom->getCoordinates();
+ for (std::size_t i = 0; i < pts->size(); i++) {
+ CoordinateXY p;
+ pts->getAt(i, p);
+ ptSet.insert(p);
+ }
+ return;
+ }
+
+ std::vector<const LineString*>
+ extractLines(const Geometry& geom)
+ {
+ return LineStringExtracter::getLines(&geom);
+ }
+
+};
+
+typedef test_group<test_linearboundary_data> group;
+typedef group::object object;
+
+group test_linearboundary_group("geos::operation::relateng::LinearBoundary");
+
+//
+// Test Cases
+//
+
+// testLineMod2
+template<>
+template<>
+void object::test<1> ()
+{
+ checkLinearBoundary("LINESTRING (0 0, 9 9)",
+ BoundaryNodeRule::getBoundaryRuleMod2(),
+ "MULTIPOINT((0 0), (9 9))");
+}
+
+// testLines2Mod2
+template<>
+template<>
+void object::test<2> ()
+{
+ checkLinearBoundary("MULTILINESTRING ((0 0, 9 9), (9 9, 5 1))",
+ BoundaryNodeRule::getBoundaryRuleMod2(),
+ "MULTIPOINT((0 0), (5 1))");
+}
+
+// testLines3Mod2
+template<>
+template<>
+void object::test<3> ()
+{
+ checkLinearBoundary("MULTILINESTRING ((0 0, 9 9), (9 9, 5 1), (9 9, 1 5))",
+ BoundaryNodeRule::getBoundaryRuleMod2(),
+ "MULTIPOINT((0 0), (5 1), (1 5), (9 9))");
+}
+
+// testLines3Monvalent
+template<>
+template<>
+void object::test<4> ()
+{
+ checkLinearBoundary("MULTILINESTRING ((0 0, 9 9), (9 9, 5 1), (9 9, 1 5))",
+ BoundaryNodeRule::getBoundaryMonovalentEndPoint(),
+ "MULTIPOINT((0 0), (5 1), (1 5))");
+}
+
+
+
+
+
+
+
+} // namespace tut
-----------------------------------------------------------------------
Summary of changes:
.../geos/operation/relateng/LineStringExtracter.h | 77 +++++++++++
src/operation/relateng/LineStringExtracter.cpp | 87 ++++++++++++
src/operation/relateng/LinearBoundary.cpp | 7 +-
.../unit/operation/relateng/LinearBoundaryTest.cpp | 147 +++++++++++++++++++++
4 files changed, 315 insertions(+), 3 deletions(-)
create mode 100644 include/geos/operation/relateng/LineStringExtracter.h
create mode 100644 src/operation/relateng/LineStringExtracter.cpp
create mode 100644 tests/unit/operation/relateng/LinearBoundaryTest.cpp
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list