[geos-commits] [SCM] GEOS branch main updated. a31dd3557f0c1b9b7365de8e665d00492833a232
git at osgeo.org
git at osgeo.org
Tue May 6 09:49:49 PDT 2025
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 a31dd3557f0c1b9b7365de8e665d00492833a232 (commit)
from 4b9a5ad063a7ea31662d6cd054a123b8b32099a6 (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 a31dd3557f0c1b9b7365de8e665d00492833a232
Author: Aurele Ferotin <aurele.ferotin at icloud.com>
Date: Tue May 6 18:49:30 2025 +0200
Add GEOSGeoJSONWriter_setOutputDimension and GEOSGeoJSONWriter_getOutputDimension (#1260)
diff --git a/capi/geos_c.cpp b/capi/geos_c.cpp
index 19f340be3..87b72163c 100644
--- a/capi/geos_c.cpp
+++ b/capi/geos_c.cpp
@@ -1607,6 +1607,18 @@ extern "C" {
return GEOSGeoJSONWriter_writeGeometry_r(handle, writer, g, indent);
}
+ void
+ GEOSGeoJSONWriter_setOutputDimension(GeoJSONWriter* writer, int dim)
+ {
+ GEOSGeoJSONWriter_setOutputDimension_r(handle, writer, dim);
+ }
+
+ int
+ GEOSGeoJSONWriter_getOutputDimension(GeoJSONWriter* writer)
+ {
+ return GEOSGeoJSONWriter_getOutputDimension_r(handle, writer);
+ }
+
//-----------------------------------------------------------------
// Prepared Geometry
diff --git a/capi/geos_c.h.in b/capi/geos_c.h.in
index 30e7bb960..6d32e95ba 100644
--- a/capi/geos_c.h.in
+++ b/capi/geos_c.h.in
@@ -2201,6 +2201,17 @@ extern char GEOS_DLL *GEOSGeoJSONWriter_writeGeometry_r(
const GEOSGeometry* g,
int indent);
+/** \see GEOSGeoJSONWriter_setOutputDimension */
+extern void GEOS_DLL GEOSGeoJSONWriter_setOutputDimension_r(
+ GEOSContextHandle_t handle,
+ GEOSGeoJSONWriter *writer,
+ int dim);
+
+/** \see GEOSGeoJSONWriter_getOutputDimension */
+extern int GEOS_DLL GEOSGeoJSONWriter_getOutputDimension_r(
+ GEOSContextHandle_t handle,
+ GEOSGeoJSONWriter *writer);
+
/** \see GEOSFree */
extern void GEOS_DLL GEOSFree_r(
GEOSContextHandle_t handle,
@@ -6223,6 +6234,27 @@ extern char GEOS_DLL *GEOSGeoJSONWriter_writeGeometry(
const GEOSGeometry* g,
int indent);
+/**
+* Set the output dimensionality of the writer. Either
+* 2 or 3 dimensions.
+* \param writer A \ref GEOSGeoJSONWriter.
+* \param dim The dimensionality desired.
+*
+* \since 3.14
+*/
+extern void GEOS_DLL GEOSGeoJSONWriter_setOutputDimension(
+ GEOSGeoJSONWriter *writer,
+ int dim);
+
+/**
+* Reads the current output dimension from a \ref GEOSGeoJSONWriter.
+* \param writer A \ref GEOSGeoJSONWriter.
+* \return The current dimension.
+*
+* \since 3.14
+*/
+extern int GEOS_DLL GEOSGeoJSONWriter_getOutputDimension(GEOSGeoJSONWriter *writer);
+
///@}
#endif /* #ifndef GEOS_USE_ONLY_R_API */
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 75536a98d..5c2080115 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -3781,6 +3781,22 @@ extern "C" {
});
}
+ void
+ GEOSGeoJSONWriter_setOutputDimension_r(GEOSContextHandle_t extHandle, GeoJSONWriter* writer, int dim)
+ {
+ execute(extHandle, [&]() {
+ writer->setOutputDimension(static_cast<uint8_t>(dim));
+ });
+ }
+
+ int
+ GEOSGeoJSONWriter_getOutputDimension_r(GEOSContextHandle_t extHandle, GeoJSONWriter* writer)
+ {
+ return execute(extHandle, -1, [&]() {
+ return writer->getOutputDimension();
+ });
+ }
+
//-----------------------------------------------------------------
// Prepared Geometry
diff --git a/tests/unit/capi/GEOSGeoJSONWriterTest.cpp b/tests/unit/capi/GEOSGeoJSONWriterTest.cpp
new file mode 100644
index 000000000..e9bfe5281
--- /dev/null
+++ b/tests/unit/capi/GEOSGeoJSONWriterTest.cpp
@@ -0,0 +1,79 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geosgeojsonwriter_data : public capitest::utility {
+
+ test_geosgeojsonwriter_data() :
+ geojsonwriter_(GEOSGeoJSONWriter_create()),
+ geojson_(nullptr)
+ {}
+
+ ~test_geosgeojsonwriter_data() {
+ GEOSGeoJSONWriter_destroy(geojsonwriter_);
+ GEOSFree(geojson_);
+ }
+
+ void
+ test_writer_geojson(std::string const& geojson)
+ {
+ test_writer_geojson(geojson, geojson);
+ }
+
+ void
+ test_writer_geojson(std::string const& geojson, std::string const& expected)
+ {
+ GEOSGeoJSONReader* reader = GEOSGeoJSONReader_create();
+ GEOSGeometry* geom1 = GEOSGeoJSONReader_readGeometry(reader, &geojson[0]);
+ ensure(nullptr != geom1);
+
+ char* wkt_c = GEOSGeoJSONWriter_writeGeometry(geojsonwriter_, geom1, -1);
+ std::string out(wkt_c);
+ free(wkt_c);
+ GEOSGeom_destroy(geom1);
+ GEOSGeoJSONReader_destroy(reader);
+
+ ensure_equals(out, expected);
+ }
+
+ GEOSGeoJSONWriter* geojsonwriter_;
+ char* geojson_;
+};
+
+typedef test_group<test_geosgeojsonwriter_data> group;
+typedef group::object object;
+
+group test_geosgeojsonwriter("capi::GEOSGeoJSONWriter");
+
+// Check default output dimension 3
+template<>
+template<>
+void object::test<1>()
+{
+ ensure_equals(GEOSGeoJSONWriter_getOutputDimension(geojsonwriter_), 3);
+
+ test_writer_geojson("{\"type\":\"Point\",\"coordinates\":[10.0,13.0]}");
+ test_writer_geojson("{\"type\":\"Point\",\"coordinates\":[10.0,13.0,3.0]}");
+}
+
+// Check writer with output dimension 2
+template<>
+template<>
+void object::test<2>()
+{
+ GEOSGeoJSONWriter_setOutputDimension(geojsonwriter_, 2);
+ ensure_equals("getOutputDimension_2", GEOSGeoJSONWriter_getOutputDimension(geojsonwriter_), 2);
+
+ test_writer_geojson("{\"type\":\"Point\",\"coordinates\":[10.0,13.0]}");
+ test_writer_geojson("{\"type\":\"Point\",\"coordinates\":[10.0,13.0,3.0]}", "{\"type\":\"Point\",\"coordinates\":[10.0,13.0]}");
+}
+
+} // namespace tut
+
-----------------------------------------------------------------------
Summary of changes:
capi/geos_c.cpp | 12 +++++
capi/geos_c.h.in | 32 +++++++++++++
capi/geos_ts_c.cpp | 16 +++++++
tests/unit/capi/GEOSGeoJSONWriterTest.cpp | 79 +++++++++++++++++++++++++++++++
4 files changed, 139 insertions(+)
create mode 100644 tests/unit/capi/GEOSGeoJSONWriterTest.cpp
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list