[geos-commits] [SCM] GEOS branch main-relate-ng updated. 70c036e84ba2d1f5116b838127932bd4f597f1c3
git at osgeo.org
git at osgeo.org
Mon Aug 12 12:07:35 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 70c036e84ba2d1f5116b838127932bd4f597f1c3 (commit)
from b3a3490336b917576d8f14538d680d7ec24dadc0 (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 70c036e84ba2d1f5116b838127932bd4f597f1c3
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Mon Aug 12 12:07:02 2024 -0700
Add prepared relate, c++ and capi bindings.
diff --git a/capi/geos_c.cpp b/capi/geos_c.cpp
index 98025b7a9..ab889455c 100644
--- a/capi/geos_c.cpp
+++ b/capi/geos_c.cpp
@@ -1603,6 +1603,18 @@ extern "C" {
return GEOSPreparedWithin_r(handle, pg1, g2);
}
+ char *
+ GEOSPreparedRelate(const geos::geom::prep::PreparedGeometry* pg1, const Geometry* g2)
+ {
+ return GEOSPreparedRelate_r(handle, pg1, g2);
+ }
+
+ char
+ GEOSPreparedRelatePattern(const geos::geom::prep::PreparedGeometry* pg1, const Geometry* g2, const char* pat)
+ {
+ return GEOSPreparedRelatePattern_r(handle, pg1, g2, pat);
+ }
+
CoordinateSequence*
GEOSPreparedNearestPoints(const geos::geom::prep::PreparedGeometry* g1, const Geometry* g2)
{
diff --git a/capi/geos_c.h.in b/capi/geos_c.h.in
index 124d26524..7eebb1896 100644
--- a/capi/geos_c.h.in
+++ b/capi/geos_c.h.in
@@ -1281,6 +1281,19 @@ extern char GEOS_DLL GEOSPreparedWithin_r(
const GEOSPreparedGeometry* pg1,
const GEOSGeometry* g2);
+/** \see GEOSPreparedRelate */
+extern char GEOS_DLL * GEOSPreparedRelate_r(
+ GEOSContextHandle_t handle,
+ const GEOSPreparedGeometry* pg1,
+ const GEOSGeometry* g2);
+
+/** \see GEOSPreparedRelatePattern */
+extern char GEOS_DLL GEOSPreparedRelatePattern_r(
+ GEOSContextHandle_t handle,
+ const GEOSPreparedGeometry* pg1,
+ const GEOSGeometry* g2,
+ const char* im);
+
/** \see GEOSPreparedNearestPoints */
extern GEOSCoordSequence GEOS_DLL *GEOSPreparedNearestPoints_r(
GEOSContextHandle_t handle,
@@ -5188,6 +5201,44 @@ extern char GEOS_DLL GEOSPreparedWithin(
const GEOSPreparedGeometry* pg1,
const GEOSGeometry* g2);
+/**
+* Use a \ref GEOSPreparedGeometry do a high performance
+* calculation of the DE9IM relationship between the
+* prepared and provided geometry, and compare that
+* relationship to the provided DE9IM, returning
+* true if the patterns are consistent and false otherwise.
+* \param pg1 The prepared geometry
+* \param g2 The geometry to test
+* \param pat The DE9IM pattern to test
+* \returns 1 on true, 0 on false, 2 on exception
+* \see GEOSPrepare
+* \see GEOSRelate
+* \see GEOSPreparedRelatePattern
+*
+* \since 3.13
+*/
+extern char GEOS_DLL * GEOSPreparedRelate(
+ const GEOSPreparedGeometry* pg1,
+ const GEOSGeometry* g2);
+
+/**
+* Use a \ref GEOSPreparedGeometry do a high performance
+* calculation of the DE9IM relationship between the
+* prepared and provided geometry.
+* \param pg1 The prepared geometry
+* \param g2 The geometry to test
+* \returns The DE9IM relate pattern string
+* \see GEOSPrepare
+* \see GEOSRelatePattern
+* \see GEOSPreparedRelate
+*
+* \since 3.13
+*/
+extern char GEOS_DLL GEOSPreparedRelatePattern(
+ const GEOSPreparedGeometry* pg1,
+ const GEOSGeometry* g2,
+ const char* pat);
+
/**
* Use a \ref GEOSPreparedGeometry do a high performance
* calculation to find the nearest points between the
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index d16cd0b55..64aaf8e3e 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -3750,6 +3750,24 @@ extern "C" {
});
}
+ char *
+ GEOSPreparedRelate_r(GEOSContextHandle_t extHandle,
+ const geos::geom::prep::PreparedGeometry* pg, const Geometry* g)
+ {
+ return execute(extHandle, [&]() -> char * {
+ return gstrdup(pg->relate(g));
+ });
+ }
+
+ char
+ GEOSPreparedRelatePattern_r(GEOSContextHandle_t extHandle,
+ const geos::geom::prep::PreparedGeometry* pg, const Geometry* g, const char* pat)
+ {
+ return execute(extHandle, 2, [&]() {
+ return pg->relate(g, std::string(pat));
+ });
+ }
+
CoordinateSequence*
GEOSPreparedNearestPoints_r(GEOSContextHandle_t extHandle,
const geos::geom::prep::PreparedGeometry* pg, const Geometry* g)
diff --git a/include/geos/geom/prep/BasicPreparedGeometry.h b/include/geos/geom/prep/BasicPreparedGeometry.h
index 4653aa15f..dcd9fe3a6 100644
--- a/include/geos/geom/prep/BasicPreparedGeometry.h
+++ b/include/geos/geom/prep/BasicPreparedGeometry.h
@@ -179,6 +179,16 @@ public:
*/
bool within(const geom::Geometry* g) const override;
+ /**
+ * Default implementation.
+ */
+ std::string relate(const geom::Geometry* g) const override;
+
+ /**
+ * Default implementation.
+ */
+ bool relate(const geom::Geometry* g, const std::string& pat) const override;
+
/**
* Default implementation.
*/
diff --git a/include/geos/geom/prep/PreparedGeometry.h b/include/geos/geom/prep/PreparedGeometry.h
index d0cf2379b..736950223 100644
--- a/include/geos/geom/prep/PreparedGeometry.h
+++ b/include/geos/geom/prep/PreparedGeometry.h
@@ -227,6 +227,28 @@ public:
*
*/
virtual bool isWithinDistance(const geom::Geometry* geom, double dist) const = 0;
+
+ /** \brief
+ * Compares the prepared geometry to the given geometry
+ * and returns the DE9IM intersection matrix as a string.
+ *
+ * @param geom the Geometry to test the
+ * @return the DE9IM matrix
+ */
+ virtual std::string relate(const geom::Geometry* g) const = 0;
+
+ /** \brief
+ * Compares the prepared geometry to the given geometry
+ * and the provided DE9IM pattern, and returns true if the
+ * pattern is consistent with the relationship between the
+ * prepared and provided geometries.
+ *
+ * @param geom the Geometry to test the distance to
+ * @param pat the DE9IM pattern
+ * @return true if the patterns are consistent
+ */
+ virtual bool relate(const geom::Geometry* g, const std::string& pat) const = 0;
+
};
diff --git a/include/geos/operation/relateng/RelateNG.h b/include/geos/operation/relateng/RelateNG.h
index ad9f3608e..f9b0e92b7 100644
--- a/include/geos/operation/relateng/RelateNG.h
+++ b/include/geos/operation/relateng/RelateNG.h
@@ -271,8 +271,8 @@ public:
bool covers(const Geometry* a);
bool coveredBy(const Geometry* a);
bool equalsTopo(const Geometry* a);
- bool relate(const Geometry* a, const std::string& imPattern);
-
+ bool relate(const Geometry* a, const std::string& pat);
+ std::string relate(const Geometry* a);
};
diff --git a/src/geom/prep/BasicPreparedGeometry.cpp b/src/geom/prep/BasicPreparedGeometry.cpp
index 1c7df4322..9dac0b965 100644
--- a/src/geom/prep/BasicPreparedGeometry.cpp
+++ b/src/geom/prep/BasicPreparedGeometry.cpp
@@ -149,6 +149,19 @@ BasicPreparedGeometry::within(const geom::Geometry* g) const
return getRelateNG()->within(g);
}
+bool
+BasicPreparedGeometry::relate(const geom::Geometry* g, const std::string& pat) const
+{
+ return getRelateNG()->relate(g, pat);
+}
+
+std::string
+BasicPreparedGeometry::relate(const geom::Geometry* g) const
+{
+ return getRelateNG()->relate(g);
+}
+
+
std::unique_ptr<geom::CoordinateSequence>
BasicPreparedGeometry::nearestPoints(const geom::Geometry* g) const
{
diff --git a/src/operation/relateng/RelateNG.cpp b/src/operation/relateng/RelateNG.cpp
index b550b711b..f09a96504 100644
--- a/src/operation/relateng/RelateNG.cpp
+++ b/src/operation/relateng/RelateNG.cpp
@@ -268,6 +268,14 @@ RelateNG::relate(const Geometry* a, const std::string& imPattern)
return evaluate(a, imPattern);
}
+/* public */
+std::string
+RelateNG::relate(const Geometry* a)
+{
+ RelateNG rng(a, false);
+ return rng.evaluate(a)->toString();
+}
+
/************************************************************************/
/* public static */
diff --git a/tests/unit/capi/GEOSPreparedGeometryTest.cpp b/tests/unit/capi/GEOSPreparedGeometryTest.cpp
index 56d852ccc..94da91cbb 100644
--- a/tests/unit/capi/GEOSPreparedGeometryTest.cpp
+++ b/tests/unit/capi/GEOSPreparedGeometryTest.cpp
@@ -451,7 +451,36 @@ void object::test<16>()
ensure(geom1_);
prepGeom1_ = GEOSPrepare(geom1_);
- ensure("curved geometries not supported", prepGeom1_ == nullptr);
+ ensure("curved geometries not supporteds", prepGeom1_ == nullptr);
+}
+
+
+template<>
+template<>
+void object::test<17>()
+{
+ geom1_ = fromWKT("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))");
+ geom2_ = fromWKT("POLYGON((0.5 0.5, 1.5 0.5, 1.5 1.5, 0.5 1.5, 0.5 0.5))");
+
+ ensure(geom1_);
+ ensure(geom2_);
+
+ prepGeom1_ = GEOSPrepare(geom1_);
+
+ ensure_equals("prepTouches1", GEOSPreparedTouches(prepGeom1_, geom2_), GEOSTouches(geom1_, geom2_));
+ ensure_equals("prepTouches2", GEOSPreparedTouches(prepGeom1_, geom2_), GEOSTouches(geom1_, geom2_));
+ ensure_equals("prepOverlaps1", GEOSPreparedOverlaps(prepGeom1_, geom2_), GEOSOverlaps(geom1_, geom2_));
+ ensure_equals("prepOverlaps2", GEOSPreparedOverlaps(prepGeom1_, geom2_), GEOSOverlaps(geom1_, geom2_));
+ ensure_equals("prepCrosses1", GEOSPreparedCrosses(prepGeom1_, geom2_), GEOSCrosses(geom1_, geom2_));
+ ensure_equals("prepCrosses2", GEOSPreparedCrosses(prepGeom1_, geom2_), GEOSCrosses(geom1_, geom2_));
+ ensure_equals("prepDisjoint1", GEOSPreparedDisjoint(prepGeom1_, geom2_), GEOSDisjoint(geom1_, geom2_));
+ ensure_equals("prepDisjoint2", GEOSPreparedDisjoint(prepGeom1_, geom2_), GEOSDisjoint(geom1_, geom2_));
+
+ char* r1 = GEOSPreparedRelate(prepGeom1_, geom2_);
+ char* r2 = GEOSRelate(geom1_, geom2_);
+ ensure_equals("prepRelate1", std::string(r1), std::string(r2));
+ GEOSFree(r1);
+ GEOSFree(r2);
}
} // namespace tut
diff --git a/tests/unit/capi/capi_test_utils.h b/tests/unit/capi/capi_test_utils.h
index 5f2d0cf04..2666d1479 100644
--- a/tests/unit/capi/capi_test_utils.h
+++ b/tests/unit/capi/capi_test_utils.h
@@ -23,6 +23,7 @@ namespace capitest {
GEOSGeometry* result_ = nullptr;
GEOSGeometry* expected_ = nullptr;
char* wkt_ = nullptr;
+ char* str_ = nullptr;
utility()
{
@@ -35,32 +36,19 @@ namespace capitest {
~utility()
{
- if (wktw_)
- GEOSWKTWriter_destroy(wktw_);
- if (geom1_) {
- GEOSGeom_destroy(geom1_);
- }
- if (geom2_) {
- GEOSGeom_destroy(geom2_);
- }
- if (geom3_) {
- GEOSGeom_destroy(geom3_);
- }
- if (input_) {
- GEOSGeom_destroy(input_);
- }
- if (result_) {
- GEOSGeom_destroy(result_);
- }
- if (expected_) {
- GEOSGeom_destroy(expected_);
- }
- if (wkt_) {
- GEOSFree(wkt_);
- }
+ if (wktw_) GEOSWKTWriter_destroy(wktw_);
+ if (geom1_) GEOSGeom_destroy(geom1_);
+ if (geom2_) GEOSGeom_destroy(geom2_);
+ if (geom3_) GEOSGeom_destroy(geom3_);
+ if (input_) GEOSGeom_destroy(input_);
+ if (result_) GEOSGeom_destroy(result_);
+ if (expected_) GEOSGeom_destroy(expected_);
+ if (wkt_) GEOSFree(wkt_);
+ if (str_) GEOSFree(str_);
finishGEOS();
}
+
static void notice(GEOS_PRINTF_FORMAT const char* fmt, ...) GEOS_PRINTF_FORMAT_ATTR(1, 2)
{
std::fprintf(stdout, "NOTICE: ");
diff --git a/tests/unit/geom/prep/PreparedGeometryTest.cpp b/tests/unit/geom/prep/PreparedGeometryTest.cpp
index c1df1abac..3934af90c 100644
--- a/tests/unit/geom/prep/PreparedGeometryTest.cpp
+++ b/tests/unit/geom/prep/PreparedGeometryTest.cpp
@@ -99,4 +99,5 @@ void object::test<3>
ensure( pg1->contains(g2.get()) );
}
+
} // namespace tut
diff --git a/tests/unit/operation/relateng/RelateNGTest.h b/tests/unit/operation/relateng/RelateNGTest.h
index a5664825b..c81544a4f 100644
--- a/tests/unit/operation/relateng/RelateNGTest.h
+++ b/tests/unit/operation/relateng/RelateNGTest.h
@@ -35,14 +35,14 @@ struct test_relateng_support {
auto prep_b = RelateNG::prepare(b.get());
ensure_equals("equalsTopo", prep_a->equalsTopo(b.get()), a->equals(b.get()));
ensure_equals("intersects", prep_a->intersects(b.get()), a->intersects(b.get()));
- ensure_equals("disjoint", prep_a->disjoint(b.get()), a->disjoint(b.get()));
- ensure_equals("covers", prep_a->covers(b.get()), a->covers(b.get()));
- ensure_equals("coveredby", prep_a->coveredBy(b.get()), a->coveredBy(b.get()));
- ensure_equals("within", prep_a->within(b.get()), a->within(b.get()));
- ensure_equals("contains", prep_a->contains(b.get()), a->contains(b.get()));
- ensure_equals("crosses", prep_a->crosses(b.get()), a->crosses(b.get()));
- ensure_equals("touches", prep_a->touches(b.get()), a->touches(b.get()));
- ensure_equals("relate", prep_a->relate(b.get()), a->relate(b.get())->toString());
+ ensure_equals("disjoint", prep_a->disjoint(b.get()), a->disjoint(b.get()));
+ ensure_equals("covers", prep_a->covers(b.get()), a->covers(b.get()));
+ ensure_equals("coveredby", prep_a->coveredBy(b.get()), a->coveredBy(b.get()));
+ ensure_equals("within", prep_a->within(b.get()), a->within(b.get()));
+ ensure_equals("contains", prep_a->contains(b.get()), a->contains(b.get()));
+ ensure_equals("crosses", prep_a->crosses(b.get()), a->crosses(b.get()));
+ ensure_equals("touches", prep_a->touches(b.get()), a->touches(b.get()));
+ ensure_equals("relate", prep_a->relate(b.get()), a->relate(b.get())->toString());
}
void checkIntersectsDisjoint(const std::string& wkta, const std::string& wktb, bool expectedValue)
-----------------------------------------------------------------------
Summary of changes:
capi/geos_c.cpp | 12 ++++++
capi/geos_c.h.in | 51 ++++++++++++++++++++++++++
capi/geos_ts_c.cpp | 18 +++++++++
include/geos/geom/prep/BasicPreparedGeometry.h | 10 +++++
include/geos/geom/prep/PreparedGeometry.h | 22 +++++++++++
include/geos/operation/relateng/RelateNG.h | 4 +-
src/geom/prep/BasicPreparedGeometry.cpp | 13 +++++++
src/operation/relateng/RelateNG.cpp | 8 ++++
tests/unit/capi/GEOSPreparedGeometryTest.cpp | 31 +++++++++++++++-
tests/unit/capi/capi_test_utils.h | 34 ++++++-----------
tests/unit/geom/prep/PreparedGeometryTest.cpp | 1 +
tests/unit/operation/relateng/RelateNGTest.h | 16 ++++----
12 files changed, 186 insertions(+), 34 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list