[geos-commits] [SCM] GEOS branch main updated. 9e3aa68491ca56a93181e6a11272bb1feef06161

git at osgeo.org git at osgeo.org
Thu Sep 9 16:19:31 PDT 2021


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  9e3aa68491ca56a93181e6a11272bb1feef06161 (commit)
      from  dd26e4a6d97cd6dd1857736465270ac27ccaf875 (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 9e3aa68491ca56a93181e6a11272bb1feef06161
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Thu Sep 9 16:18:26 2021 -0700

    Support ISO WKB in WKBWriter.
    Added GEOSWKBWriter_setFlavor and GEOSWKBWriter_getFlavor
    to the CAPI.
    Closes #466

diff --git a/NEWS b/NEWS
index da9ee04..f016ecb 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ Changes in 3.10.0
   - CAPI: GEOSMakeValidWithParams new validity enforcement approach from
           https://github.com/locationtech/jts/pull/704, uses GeometryFixer
           (Paul Ramsey, Martin Davis)
+  - CAPI: GEOSWKBWriter_getFlavor, GEOSWKBWriter_setFlavor support
+          outputting ISO or Extended WKB flavors (#466, Paul Ramsey)
 
 - Fixes/Improvements:
   - Preserve ordering of lines in overlay results (Martin Davis)
diff --git a/capi/geos_c.cpp b/capi/geos_c.cpp
index f4f3ed0..6134356 100644
--- a/capi/geos_c.cpp
+++ b/capi/geos_c.cpp
@@ -1281,6 +1281,18 @@ extern "C" {
         GEOSWKBWriter_setByteOrder_r(handle, writer, newByteOrder);
     }
 
+    int
+    GEOSWKBWriter_getFlavor(const GEOSWKBWriter* writer)
+    {
+        return GEOSWKBWriter_getFlavor_r(handle, writer);
+    }
+
+    void
+    GEOSWKBWriter_setFlavor(GEOSWKBWriter* writer, int newFlavor)
+    {
+        GEOSWKBWriter_setFlavor_r(handle, writer, newFlavor);
+    }
+
     char
     GEOSWKBWriter_getIncludeSRID(const GEOSWKBWriter* writer)
     {
diff --git a/capi/geos_c.h.in b/capi/geos_c.h.in
index 68d1df3..0a3cb9d 100644
--- a/capi/geos_c.h.in
+++ b/capi/geos_c.h.in
@@ -218,7 +218,7 @@ enum GEOSGeomTypes {
 *
 * \see GEOSWKBWriter_setByteOrder
 */
-enum GEOSByteOrders {
+enum GEOSWKBByteOrders {
     /** Big Endian */
     GEOS_WKB_XDR = 0,
     /** Little Endian */
@@ -226,6 +226,22 @@ enum GEOSByteOrders {
 };
 
 /**
+* Well-known binary flavors to use
+* when writing to WKB. ISO flavour is
+* more standard. Extended flavour supports
+* 3D and SRID embedding. GEOS reads both
+* transparently.
+*
+* \see GEOSWKBWriter_setFlavor
+*/
+enum GEOSWKBFlavors {
+    /** Extended */
+    GEOS_WKB_EXTENDED = 1,
+    /** ISO */
+    GEOS_WKB_ISO = 2
+};
+
+/**
 * Callback function for use in spatial index search calls. Pass into
 * the query function and handle query results as the index
 * returns them.
@@ -1734,6 +1750,17 @@ extern void GEOS_DLL GEOSWKBWriter_setByteOrder_r(
     GEOSWKBWriter* writer,
     int byteOrder);
 
+/** \see GEOSWKBWriter_getFlavor */
+extern int GEOS_DLL GEOSWKBWriter_getFlavor_r(
+    GEOSContextHandle_t handle,
+    const GEOSWKBWriter* writer);
+
+/** \see GEOSWKBWriter_setFlavor */
+extern void GEOS_DLL GEOSWKBWriter_setFlavor_r(
+    GEOSContextHandle_t handle,
+    GEOSWKBWriter* writer,
+    int flavor);
+
 /** \see GEOSWKBWriter_getIncludeSRID */
 extern char GEOS_DLL GEOSWKBWriter_getIncludeSRID_r(
     GEOSContextHandle_t handle,
@@ -4251,7 +4278,7 @@ extern void GEOS_DLL GEOSWKBWriter_setOutputDimension(
 * Find whether the writer will use WKB
 * [byte order](https://en.wikipedia.org/wiki/Endianness)
 * that is big or little endian.
-* The return value is a member of \ref GEOSByteOrders.
+* The return value is a member of \ref GEOSWKBByteOrders.
 * \param writer The writer to read byte order from
 * \return The current byte order
 */
@@ -4260,7 +4287,7 @@ extern int GEOS_DLL GEOSWKBWriter_getByteOrder(
 
 /**
 * Set the output byte order of the writer, using
-* a value from \ref GEOSByteOrders enum.
+* a value from \ref GEOSWKBByteOrders enum.
 * \param writer The writer to set byte order on
 * \param byteOrder Desired byte order
 */
@@ -4269,6 +4296,31 @@ extern void GEOS_DLL GEOSWKBWriter_setByteOrder(
     int byteOrder);
 
 /**
+* Find whether the writer will use
+* [WKB](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary)
+* that is ISO flavor or "extended" flavor. The flavor
+* determines how extra dimensionality is encoded with the
+* type number, and whether SRID can be included in the WKB.
+* ISO flavor does not support SRID embedding. ISO flavor
+* is "more standard" for 3D output. GEOS can read both flavors.
+* The return value is a member of \ref GEOSWKBFlavors.
+* \param writer The writer to read flavor from
+* \return The current flavor
+*/
+extern int GEOS_DLL GEOSWKBWriter_getFlavor(
+    const GEOSWKBWriter* writer);
+
+/**
+* Set the output flavor of the writer, using
+* a value from \ref GEOSWKBFlavors enum.
+* \param writer The writer to set flavor on
+* \param flavor Desired flavor
+*/
+extern void GEOS_DLL GEOSWKBWriter_setFlavor(
+    GEOSWKBWriter* writer,
+    int flavor);
+
+/**
 * Read the current SRID embedding value from the writer.
 * \param writer The writer to check SRID value on
 */
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 092e0e2..ee4beea 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -3058,6 +3058,22 @@ extern "C" {
         });
     }
 
+    int
+    GEOSWKBWriter_getFlavor_r(GEOSContextHandle_t extHandle, const GEOSWKBWriter* writer)
+    {
+        return execute(extHandle, -1, [&]{
+            return writer->getFlavor();
+        });
+    }
+
+    void
+    GEOSWKBWriter_setFlavor_r(GEOSContextHandle_t extHandle, GEOSWKBWriter* writer, int flavor)
+    {
+        execute(extHandle, [&]{
+            writer->setFlavor(flavor);
+        });
+    }
+
     /* GeoJSON Reader */
     GeoJSONReader*
     GEOSGeoJSONReader_create_r(GEOSContextHandle_t extHandle)
diff --git a/include/geos/io/WKBConstants.h b/include/geos/io/WKBConstants.h
index 59ab732..147a225 100644
--- a/include/geos/io/WKBConstants.h
+++ b/include/geos/io/WKBConstants.h
@@ -17,8 +17,7 @@
  *
  **********************************************************************/
 
-#ifndef GEOS_IO_WKBCONSTANTS_H
-#define GEOS_IO_WKBCONSTANTS_H
+#pragma once
 
 namespace geos {
 namespace io {
@@ -26,22 +25,28 @@ namespace io {
 /// Constant values used by the WKB format
 namespace WKBConstants {
 
-/// Big Endian
-const int wkbXDR = 0;
+    enum byteOrder {
+        wkbXDR = 0,
+        wkbNDR = 1
+    };
+
+    enum wkbType {
+        wkbPoint = 1,
+        wkbLineString = 2,
+        wkbPolygon = 3,
+        wkbMultiPoint = 4,
+        wkbMultiLineString = 5,
+        wkbMultiPolygon = 6,
+        wkbGeometryCollection = 7
+    };
+
+    enum wkbFlavour {
+        wkbIso = 1,
+        wkbExtended = 2
+    };
 
-/// Little Endian
-const int wkbNDR = 1;
-
-const int wkbPoint = 1;
-const int wkbLineString = 2;
-const int wkbPolygon = 3;
-const int wkbMultiPoint = 4;
-const int wkbMultiLineString = 5;
-const int wkbMultiPolygon = 6;
-const int wkbGeometryCollection = 7;
 }
 
 } // namespace geos::io
 } // namespace geos
 
-#endif // #ifndef GEOS_IO_WKBCONSTANTS_H
diff --git a/include/geos/io/WKBWriter.h b/include/geos/io/WKBWriter.h
index fd15f49..a648e1d 100644
--- a/include/geos/io/WKBWriter.h
+++ b/include/geos/io/WKBWriter.h
@@ -23,6 +23,7 @@
 #include <geos/export.h>
 
 #include <geos/util/Machine.h> // for getMachineByteOrder
+#include <geos/io/WKBConstants.h>
 #include <iosfwd>
 #include <cstdint>
 #include <cstddef>
@@ -86,20 +87,24 @@ public:
      * @param incudeSRID true if SRID should be included in WKB (an
      * extension).
      */
-    WKBWriter(uint8_t dims = 2, int bo = getMachineByteOrder(), bool includeSRID = false);
+    WKBWriter(
+        uint8_t dims = 2,
+        int bo = getMachineByteOrder(),
+        bool includeSRID = false,
+        int flv = WKBConstants::wkbExtended);
 
     /*
      * \brief
      * Destructor.
      */
-    virtual ~WKBWriter() = default;
+    ~WKBWriter() = default;
 
     /*
      * \brief
      * Returns the output dimension used by the
      * <code>WKBWriter</code>.
      */
-    virtual uint8_t
+    uint8_t
     getOutputDimension() const
     {
         return defaultOutputDimension;
@@ -112,14 +117,14 @@ public:
      * Note that 3 indicates up to 3 dimensions will be written but
      * 2D WKB is still produced for 2D geometries.
      */
-    virtual void setOutputDimension(uint8_t newOutputDimension);
+    void setOutputDimension(uint8_t newOutputDimension);
 
     /*
      * \brief
      * Returns the byte order used by the
      * <code>WKBWriter</code>.
      */
-    virtual int
+    int
     getByteOrder() const
     {
         return byteOrder;
@@ -129,14 +134,14 @@ public:
      * Sets the byte order used by the
      * <code>WKBWriter</code>.
      */
-    virtual void setByteOrder(int newByteOrder);
+    void setByteOrder(int newByteOrder);
 
     /*
      * \brief
      * Returns whether SRID values are output by the
      * <code>WKBWriter</code>.
      */
-    virtual bool
+    bool
     getIncludeSRID() const
     {
         return includeSRID;
@@ -146,12 +151,28 @@ public:
      * Sets whether SRID values should be output by the
      * <code>WKBWriter</code>.
      */
-    virtual void
+    void
     setIncludeSRID(bool newIncludeSRID)
     {
         includeSRID = newIncludeSRID;
     }
 
+    /*
+     * \brief
+     * Returns the WKB flavor the writer will emit.
+     */
+    int
+    getFlavor() const
+    {
+        return flavor;
+    }
+
+    /*
+     * \brief
+     * Set the WKB flavor the writer will emit.
+     */
+    void setFlavor(int newFlavor);
+
     /**
      * \brief Write a Geometry to an ostream.
      *
@@ -174,10 +195,14 @@ public:
 
 private:
 
+    // 2 or 3
     uint8_t defaultOutputDimension;
     uint8_t outputDimension;
 
+    // WKBConstants::wkbwkbXDR | WKBConstants::wkbNDR
     int byteOrder;
+    // WKBConstants::wkbIso | WKBConstants::wkbExtended
+    int flavor;
 
     bool includeSRID;
 
diff --git a/src/io/WKBWriter.cpp b/src/io/WKBWriter.cpp
index 8957717..23424d1 100644
--- a/src/io/WKBWriter.cpp
+++ b/src/io/WKBWriter.cpp
@@ -18,7 +18,6 @@
 
 #include <geos/io/WKBWriter.h>
 #include <geos/io/WKBReader.h>
-#include <geos/io/WKBConstants.h>
 #include <geos/io/ByteOrderValues.h>
 #include <geos/util/IllegalArgumentException.h>
 #include <geos/geom/Coordinate.h>
@@ -45,8 +44,12 @@ using namespace geos::geom;
 namespace geos {
 namespace io { // geos.io
 
-WKBWriter::WKBWriter(uint8_t dims, int bo, bool srid):
-    defaultOutputDimension(dims), byteOrder(bo), includeSRID(srid), outStream(nullptr)
+WKBWriter::WKBWriter(uint8_t dims, int bo, bool srid, int flv)
+    : defaultOutputDimension(dims)
+    , byteOrder(bo)
+    , flavor(flv)
+    , includeSRID(srid)
+    , outStream(nullptr)
 {
     if(dims < 2 || dims > 3) {
         throw util::IllegalArgumentException("WKB output dimension must be 2 or 3");
@@ -62,10 +65,22 @@ WKBWriter::setOutputDimension(uint8_t dims)
     if(dims < 2 || dims > 3) {
         throw util::IllegalArgumentException("WKB output dimension must be 2 or 3");
     }
-
     defaultOutputDimension = dims;
 }
 
+
+/* public */
+void
+WKBWriter::setFlavor(int newFlavor)
+{
+    if (newFlavor != WKBConstants::wkbIso &&
+        newFlavor != WKBConstants::wkbExtended) {
+        throw util::IllegalArgumentException("Invalid WKB output flavour");
+    }
+    flavor = newFlavor;
+}
+
+
 void
 WKBWriter::writeHEX(const Geometry& g, std::ostream& os)
 {
@@ -83,37 +98,37 @@ void
 WKBWriter::write(const Geometry& g, std::ostream& os)
 {
     outputDimension = defaultOutputDimension;
-    if(outputDimension > g.getCoordinateDimension()) {
+    if (outputDimension > g.getCoordinateDimension()) {
         outputDimension = g.getCoordinateDimension();
     }
 
     outStream = &os;
 
-    if(const Point* x = dynamic_cast<const Point*>(&g)) {
+    if (const Point* x = dynamic_cast<const Point*>(&g)) {
         return writePoint(*x);
     }
 
-    if(const LineString* x = dynamic_cast<const LineString*>(&g)) {
+    if (const LineString* x = dynamic_cast<const LineString*>(&g)) {
         return writeLineString(*x);
     }
 
-    if(const Polygon* x = dynamic_cast<const Polygon*>(&g)) {
+    if (const Polygon* x = dynamic_cast<const Polygon*>(&g)) {
         return writePolygon(*x);
     }
 
-    if(const MultiPoint* x = dynamic_cast<const MultiPoint*>(&g)) {
+    if (const MultiPoint* x = dynamic_cast<const MultiPoint*>(&g)) {
         return writeGeometryCollection(*x, WKBConstants::wkbMultiPoint);
     }
 
-    if(const MultiLineString* x = dynamic_cast<const MultiLineString*>(&g)) {
+    if (const MultiLineString* x = dynamic_cast<const MultiLineString*>(&g)) {
         return writeGeometryCollection(*x, WKBConstants::wkbMultiLineString);
     }
 
-    if(const MultiPolygon* x = dynamic_cast<const MultiPolygon*>(&g)) {
+    if (const MultiPolygon* x = dynamic_cast<const MultiPolygon*>(&g)) {
         return writeGeometryCollection(*x, WKBConstants::wkbMultiPolygon);
     }
 
-    if(const GeometryCollection* x =
+    if (const GeometryCollection* x =
                 dynamic_cast<const GeometryCollection*>(&g)) {
         return writeGeometryCollection(*x, WKBConstants::wkbGeometryCollection);
     }
@@ -138,7 +153,7 @@ WKBWriter::writePointEmpty(const Point& g)
 void
 WKBWriter::writePoint(const Point& g)
 {
-    if(g.isEmpty()) {
+    if (g.isEmpty()) {
         return writePointEmpty(g);
     }
 
@@ -173,7 +188,7 @@ WKBWriter::writePolygon(const Polygon& g)
     writeGeometryType(WKBConstants::wkbPolygon, g.getSRID());
     writeSRID(g.getSRID());
 
-    if(g.isEmpty()) {
+    if (g.isEmpty()) {
         writeInt(0);
         return;
     }
@@ -256,20 +271,35 @@ WKBWriter::setByteOrder(int bo)
 void
 WKBWriter::writeGeometryType(int typeId, int SRID)
 {
-    int flag3D = (outputDimension == 3) ? int(0x80000000) : 0;
-    int typeInt = typeId | flag3D;
-
-    if(includeSRID && SRID != 0) {
-        typeInt = typeInt | 0x20000000;
+    if (flavor == WKBConstants::wkbExtended) {
+        int flag3D = (outputDimension == 3) ? int(0x80000000) : 0;
+        typeId |= flag3D;
+        if(includeSRID && SRID != 0) {
+            typeId |= 0x20000000;
+        }
     }
-
-    writeInt(typeInt);
+    else if (flavor == WKBConstants::wkbIso) {
+        if (outputDimension == 3) {
+            typeId += 1000;
+        }
+    }
+    else {
+        throw util::IllegalArgumentException("Unknown WKB flavor");
+    }
+    writeInt(typeId);
 }
 
 void
 WKBWriter::writeSRID(int SRID)
 {
-    if(includeSRID && SRID != 0) {
+    // Only write the SRID in if
+    // it is requested and
+    // it is non zero and
+    // the format is extended (ISO doesn't support SRID embedding)
+    if (includeSRID &&
+        SRID != 0 &&
+        flavor == WKBConstants::wkbExtended)
+    {
         writeInt(SRID);
     }
 }
diff --git a/tests/unit/capi/GEOSGeomToWKBTest.cpp b/tests/unit/capi/GEOSGeomToWKBTest.cpp
new file mode 100644
index 0000000..5a349e9
--- /dev/null
+++ b/tests/unit/capi/GEOSGeomToWKBTest.cpp
@@ -0,0 +1,204 @@
+//
+// Test Suite for C-API GEOSGeomToWKB
+
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+// std
+#include <string>
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <memory>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+// Common data used in test cases.
+struct test_capigeosgeomtowkb_data : public capitest::utility {
+
+    void
+    test_wkb(const std::string& wkt, int flavor)
+    {
+        geom1_ = GEOSGeomFromWKT(wkt.c_str());
+        ensure(nullptr != geom1_);
+
+        GEOSWKBWriter* wkbwriter = GEOSWKBWriter_create();
+        GEOSWKBWriter_setOutputDimension(wkbwriter, 3);
+        GEOSWKBWriter_setFlavor(wkbwriter, flavor);
+        std::size_t wkb_size;
+        unsigned char* wkb = GEOSWKBWriter_write(wkbwriter, geom1_, &wkb_size);
+        GEOSWKBWriter_destroy(wkbwriter);
+
+        GEOSWKBReader* wkbreader = GEOSWKBReader_create();
+        geom2_ = GEOSWKBReader_read(wkbreader, wkb, wkb_size);
+        GEOSWKBReader_destroy(wkbreader);
+        free(wkb);
+
+        GEOSWKTWriter* wktwriter = GEOSWKTWriter_create();
+        GEOSWKTWriter_setRoundingPrecision(wktwriter, 3);
+        GEOSWKTWriter_setTrim(wktwriter, 1);
+        GEOSWKTWriter_setOutputDimension(wktwriter, 3);
+        char* wkt_c = GEOSWKTWriter_write(wktwriter, geom2_);
+        GEOSWKTWriter_destroy(wktwriter);
+        std::string out(wkt_c);
+        free(wkt_c);
+
+        ensure_equals(out, wkt);
+    }
+
+    void
+    test_wkb(const std::string& wkt)
+    {
+        test_wkb(wkt, GEOS_WKB_EXTENDED);
+    }
+
+
+};
+
+typedef test_group<test_capigeosgeomtowkb_data> group;
+typedef group::object object;
+
+group test_capigeosgeomtowkb_group("capi::GEOSGeomToWKB");
+
+//
+// Test Cases
+//
+
+template<>
+template<>
+void object::test<1>
+()
+{
+    test_wkb("POINT EMPTY");
+}
+
+template<>
+template<>
+void object::test<2>
+()
+{
+    test_wkb("LINESTRING EMPTY");
+}
+
+template<>
+template<>
+void object::test<3>
+()
+{
+    test_wkb("POLYGON EMPTY");
+}
+
+template<>
+template<>
+void object::test<4>
+()
+{
+    test_wkb("MULTIPOINT EMPTY");
+}
+
+template<>
+template<>
+void object::test<5>
+()
+{
+    test_wkb("MULTILINESTRING EMPTY");
+}
+
+template<>
+template<>
+void object::test<6>
+()
+{
+    test_wkb("MULTIPOLYGON EMPTY");
+}
+
+// Comparing string based on float-point numbers does not make sense,
+// so make poor-man comparison of WKT type tag.
+
+template<>
+template<>
+void object::test<7>
+()
+{
+    test_wkb("POINT (1 2)");
+}
+
+template<>
+template<>
+void object::test<8>
+()
+{
+    test_wkb("LINESTRING (0 0, 5 5, 10 5, 10 10)");
+}
+
+template<>
+template<>
+void object::test<9>
+()
+{
+    test_wkb("POLYGON ((0 10, 5 5, 10 5, 15 10, 10 15, 5 15, 0 10))");
+}
+
+template<>
+template<>
+void object::test<10>
+()
+{
+    test_wkb("MULTIPOINT (0 0, 5 5, 10 10, 15 15, 20 20)");
+}
+
+template<>
+template<>
+void object::test<11>
+()
+{
+    test_wkb("MULTILINESTRING ((0 0, 10 0, 10 10, 0 10, 10 20), (2 2, 2 6, 6 4, 20 2))");
+}
+
+template<>
+template<>
+void object::test<12>
+()
+{
+    test_wkb("MULTIPOLYGON (((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 2 6, 6 4, 2 2)), ((60 60, 60 50, 70 40, 60 60)))");
+}
+
+template<>
+template<>
+void object::test<13>
+()
+{
+    test_wkb("POINT Z (1 2 3)");
+}
+
+template<>
+template<>
+void object::test<14>
+()
+{
+    test_wkb("LINESTRING Z (1 2 3, 4 5 6, 7 8 9)");
+}
+
+template<>
+template<>
+void object::test<15>
+()
+{
+    test_wkb("POINT Z (1 2 3)", GEOS_WKB_ISO);
+}
+
+template<>
+template<>
+void object::test<16>
+()
+{
+    test_wkb("LINESTRING Z (1 2 3, 4 5 6, 7 8 9)", GEOS_WKB_ISO);
+}
+
+} // namespace tut
+
diff --git a/tests/unit/io/WKBWriterTest.cpp b/tests/unit/io/WKBWriterTest.cpp
index fae8fbc..1c17118 100644
--- a/tests/unit/io/WKBWriterTest.cpp
+++ b/tests/unit/io/WKBWriterTest.cpp
@@ -8,6 +8,7 @@
 #include <geos/io/WKBWriter.h>
 #include <geos/io/WKTReader.h>
 #include <geos/io/WKTWriter.h>
+#include <geos/io/WKBConstants.h>
 #include <geos/geom/PrecisionModel.h>
 #include <geos/geom/GeometryFactory.h>
 #include <geos/geom/Geometry.h>
@@ -263,7 +264,43 @@ void object::test<9>
     assert(geom->equals(geom2.get()));
 }
 
+// Test writing a 3D geometry with the WKBWriter in ISO flavor
+template<>
+template<>
+void object::test<10>
+()
+{
+    auto geom = wktreader.read("POINT(-117 33 11)");
+    std::stringstream result_stream;
+
+    wkbwriter.setOutputDimension(3);
+    wkbwriter.setFlavor(geos::io::WKBConstants::wkbIso);
+    wkbwriter.write(*geom, result_stream);
+    wkbwriter.setByteOrder(0);
+
+    ensure(result_stream.str().length() == 29);
+
+    result_stream.seekg(0);
+    geom = wkbreader.read(result_stream);
+
+    ensure(geom->getCoordinateDimension() == 3);
+    ensure(geom->getCoordinate()->x == -117.0);
+    ensure(geom->getCoordinate()->y == 33.0);
+    ensure(geom->getCoordinate()->z == 11.0);
+
+    result_stream.str("");
+    wkbwriter.writeHEX(*geom, result_stream);
+    std::string actual = result_stream.str();
+    // std::cout << std::endl << actual << std::endl;
 
+    // 00 == big endian
+    // 000003E9 == 1001
+    // C05D400000000000 == -117
+    // 4040800000000000 == 33
+    // 4026000000000000 == 11
+    ensure_equals(actual,
+                  "00000003E9C05D40000000000040408000000000004026000000000000");
+}
 
 
 } // namespace tut

-----------------------------------------------------------------------

Summary of changes:
 NEWS                                  |   2 +
 capi/geos_c.cpp                       |  12 ++
 capi/geos_c.h.in                      |  58 +++++++++-
 capi/geos_ts_c.cpp                    |  16 +++
 include/geos/io/WKBConstants.h        |  35 +++---
 include/geos/io/WKBWriter.h           |  41 +++++--
 src/io/WKBWriter.cpp                  |  74 ++++++++----
 tests/unit/capi/GEOSGeomToWKBTest.cpp | 204 ++++++++++++++++++++++++++++++++++
 tests/unit/io/WKBWriterTest.cpp       |  37 ++++++
 9 files changed, 431 insertions(+), 48 deletions(-)
 create mode 100644 tests/unit/capi/GEOSGeomToWKBTest.cpp


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list