[geos-commits] [SCM] GEOS branch main updated. f603af8de7618ab110c661da4896e651f5e44ecb
git at osgeo.org
git at osgeo.org
Thu Jun 25 19:35:40 PDT 2026
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 has been updated
via f603af8de7618ab110c661da4896e651f5e44ecb (commit)
via 436ee7fbc6b7a4d710d64ff3e49f928e9ac61adc (commit)
from a4b9ba7d70b4e46143377b4013789f7534033958 (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 f603af8de7618ab110c661da4896e651f5e44ecb
Author: Daniel Baston <dbaston at gmail.com>
Date: Wed Jun 24 21:36:10 2026 -0400
C API: Add GEOSGetNumCurves, GEOSCurveN
diff --git a/capi/geos_c.cpp b/capi/geos_c.cpp
index ec799f7d3..a421eabc0 100644
--- a/capi/geos_c.cpp
+++ b/capi/geos_c.cpp
@@ -899,6 +899,18 @@ extern "C" {
return GEOSGetGeometryN_r(handle, g, n);
}
+ int
+ GEOSGetNumCurves(const Geometry* g)
+ {
+ return GEOSGetNumCurves_r(handle, g);
+ }
+
+ const Geometry*
+ GEOSGetCurveN(const Geometry* g, int n)
+ {
+ return GEOSGetCurveN_r(handle, g, n);
+ }
+
/*
* Call only on LINESTRING
* Returns NULL on exception
diff --git a/capi/geos_c.h.in b/capi/geos_c.h.in
index c6e853dea..56b0abc6c 100644
--- a/capi/geos_c.h.in
+++ b/capi/geos_c.h.in
@@ -1828,6 +1828,16 @@ extern const GEOSGeometry GEOS_DLL *GEOSGetGeometryN_r(
GEOSContextHandle_t handle,
const GEOSGeometry* g, int n);
+/** \see GEOSGetNumCurves */
+extern int GEOS_DLL GEOSGetNumCurves_r(
+ GEOSContextHandle_t handle,
+ const GEOSGeometry* g);
+
+/** \see GEOSGetCurveN */
+extern const GEOSGeometry GEOS_DLL *GEOSGetCurveN_r(
+ GEOSContextHandle_t handle,
+ const GEOSGeometry* g, int n);
+
/** \see GEOSNormalize */
extern int GEOS_DLL GEOSNormalize_r(
GEOSContextHandle_t handle,
@@ -3146,6 +3156,33 @@ extern const GEOSGeometry GEOS_DLL *GEOSGetGeometryN(
const GEOSGeometry* g,
int n);
+/**
+* Returns the number of simple curves in a CompoundCurve.
+* Returns 1 for a non-empty LineString/CircularString, and 0
+* for other inputs.
+* \param g Input geometry
+* \return Number of child curves in this geometry
+* \since 3.15
+*/
+extern int GEOS_DLL GEOSGetNumCurves(const GEOSGeometry* g);
+
+/**
+* Returns the specified sub-curve of a geometry. For a simple curve type
+* (LineString/CircularString), returns a pointer to the input.
+* Returns NULL for non-curve types (dimension != 1).
+*
+* Returned object is a pointer to internal storage and must NOT be destroyed
+* directly.
+
+* \param g Input geometry
+* \param n Sub-curve index, zero-based
+* \return A const \ref GEOSGeometry, or NULL
+* \since 3.15
+*/
+extern const GEOSGeometry GEOS_DLL *GEOSGetCurveN(
+ const GEOSGeometry* g,
+ int n);
+
/**
* Read the currently set precision value from the
* geometry and returns the grid size if it is a fixed
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index c42bf851d..7b06105cf 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -2311,6 +2311,36 @@ extern "C" {
});
}
+ int
+ GEOSGetNumCurves_r(GEOSContextHandle_t extHandle, const Geometry* g1)
+ {
+ return execute<NotInterruptible>(extHandle, -1, [&]() {
+ const Curve* curve = dynamic_cast<const Curve*>(g1);
+ if (curve) {
+ return static_cast<int>(curve->getNumCurves());
+ }
+
+ return 0;
+ });
+ }
+
+ const GEOSGeometry*
+ GEOSGetCurveN_r(GEOSContextHandle_t extHandle, const Geometry* g, int n)
+ {
+ return execute<NotInterruptible>(extHandle, [&]() -> const Geometry* {
+ if(n < 0) {
+ throw IllegalArgumentException("Index must be non-negative.");
+ }
+
+ const Curve* curve = dynamic_cast<const Curve*>(g);
+ if (curve) {
+ return curve->getCurveN(static_cast<std::size_t>(n));
+ }
+
+ return nullptr;
+ });
+ }
+
/*
* Call only on LineString, CircularString, or CompoundCurve
* Returns NULL on exception
diff --git a/tests/unit/capi/GEOSCompoundCurveTest.cpp b/tests/unit/capi/GEOSCompoundCurveTest.cpp
index a43aa63f9..6a45c69f0 100644
--- a/tests/unit/capi/GEOSCompoundCurveTest.cpp
+++ b/tests/unit/capi/GEOSCompoundCurveTest.cpp
@@ -142,4 +142,20 @@ void object::test<8>()
ensure_equals(length, geos::MATH_PI*1.5*5 + 5);
}
+template<>
+template<>
+void object::test<9>()
+{
+ set_test_name("GEOSGetNumCurves / GEOSGetCurveN");
+
+ ensure_equals(GEOSGetNumCurves(cc_), 2);
+
+ geom1_ = fromWKT("CIRCULARSTRING ZM (-5 0 6 7, 4 3 7 8 , 0 -5 8 9)");
+ geom2_ = fromWKT("LINESTRING (0 -5 8 9, -5 -5 9 10)");
+
+ ensure(GEOSGetCurveN(cc_, -1) == nullptr);
+ ensure_geometry_equals_identical(GEOSGetCurveN(cc_, 0), geom1_);
+ ensure_geometry_equals_identical(GEOSGetCurveN(cc_, 1), geom2_);
+}
+
} // namespace tut
diff --git a/tests/unit/capi/GEOSLineStringTest.cpp b/tests/unit/capi/GEOSLineStringTest.cpp
index 4beae5439..f50fa3f12 100644
--- a/tests/unit/capi/GEOSLineStringTest.cpp
+++ b/tests/unit/capi/GEOSLineStringTest.cpp
@@ -184,4 +184,30 @@ void object::test<6>
ensure_equals(length, 1);
}
+template<>
+template<>
+void object::test<7>()
+{
+ set_test_name("GEOSGetNumCurves / GEOSGetCurveN");
+
+ input_ = fromWKT("LINESTRING (1 1, 2 2)");
+
+ ensure_equals(GEOSGetNumCurves(input_), 1);
+
+ ensure(GEOSGetCurveN(input_, -1) == nullptr);
+ ensure(GEOSGetCurveN(input_, 0) == input_);
+}
+
+template<>
+template<>
+void object::test<8>()
+{
+ set_test_name("GEOSGetNumCurves(LINESTRING EMPTY)");
+
+ input_ = fromWKT("LINESTRING EMPTY");
+
+ ensure_equals(GEOSGetNumCurves(input_), 0);
+}
+
+
} // namespace tut
diff --git a/tests/unit/capi/capi_test_utils.h b/tests/unit/capi/capi_test_utils.h
index a9680cf1b..a1e5dadfb 100644
--- a/tests/unit/capi/capi_test_utils.h
+++ b/tests/unit/capi/capi_test_utils.h
@@ -181,7 +181,7 @@ namespace capitest {
}
void
- ensure_geometry_equals_identical(GEOSGeometry* g1, GEOSGeometry* g2)
+ ensure_geometry_equals_identical(const GEOSGeometry* g1, const GEOSGeometry* g2)
{
char rslt;
if (g1 == nullptr || g2 == nullptr) {
@@ -222,7 +222,7 @@ namespace capitest {
}
void
- report_not_equal(const char* tag, GEOSGeometry* g1, GEOSGeometry* g2, double tolerance, char rslt)
+ report_not_equal(const char* tag, const GEOSGeometry* g1, const GEOSGeometry* g2, double tolerance, char rslt)
{
if (rslt == 1) return;
//TODO: handle rslt exception value
commit 436ee7fbc6b7a4d710d64ff3e49f928e9ac61adc
Author: Daniel Baston <dbaston at gmail.com>
Date: Wed Jun 24 21:35:56 2026 -0400
SimpleCurve: Make getNumCurves return 0 for EMPTY curve
diff --git a/src/geom/SimpleCurve.cpp b/src/geom/SimpleCurve.cpp
index d65689714..2ea39e55c 100644
--- a/src/geom/SimpleCurve.cpp
+++ b/src/geom/SimpleCurve.cpp
@@ -267,7 +267,7 @@ SimpleCurve::getEndPoint() const
std::size_t
SimpleCurve::getNumCurves() const
{
- return 1;
+ return isEmpty() ? 0 : 1;
}
std::size_t
-----------------------------------------------------------------------
Summary of changes:
capi/geos_c.cpp | 12 ++++++++++
capi/geos_c.h.in | 37 +++++++++++++++++++++++++++++++
capi/geos_ts_c.cpp | 30 +++++++++++++++++++++++++
src/geom/SimpleCurve.cpp | 2 +-
tests/unit/capi/GEOSCompoundCurveTest.cpp | 16 +++++++++++++
tests/unit/capi/GEOSLineStringTest.cpp | 26 ++++++++++++++++++++++
tests/unit/capi/capi_test_utils.h | 4 ++--
7 files changed, 124 insertions(+), 3 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list