[geos-commits] [SCM] GEOS branch master updated. fa24fb2f3bd84cd70309f8594aa29738661e94ca

git at osgeo.org git at osgeo.org
Fri Nov 6 10:46:26 PST 2020


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, master has been updated
       via  fa24fb2f3bd84cd70309f8594aa29738661e94ca (commit)
      from  531b9e623107a325a87cc5cbf7c6a399217b3fdd (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 fa24fb2f3bd84cd70309f8594aa29738661e94ca
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Fri Nov 6 10:37:40 2020 -0800

    Correctly handle higher-dimension empty geometries in the WKB reader.

diff --git a/.gitignore b/.gitignore
index 8084631..bdb9610 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,6 +18,7 @@ Makefile
 *.swp
 *.trs
 *.exe
+.DS_Store
 macros/libtool.m4
 macros/ltoptions.m4
 macros/ltsugar.m4
diff --git a/src/geom/Point.cpp b/src/geom/Point.cpp
index 5c3d083..4536640 100644
--- a/src/geom/Point.cpp
+++ b/src/geom/Point.cpp
@@ -44,6 +44,7 @@ namespace geom { // geos::geom
 const static FixedSizeCoordinateSequence<0> emptyCoords2d(2);
 const static FixedSizeCoordinateSequence<0> emptyCoords3d(3);
 
+
 /*protected*/
 Point::Point(CoordinateSequence* newCoords, const GeometryFactory* factory)
     :
diff --git a/src/io/WKBReader.cpp b/src/io/WKBReader.cpp
index a2b21c9..aa13d29 100644
--- a/src/io/WKBReader.cpp
+++ b/src/io/WKBReader.cpp
@@ -279,6 +279,12 @@ std::unique_ptr<Point>
 WKBReader::readPoint()
 {
     readCoordinate();
+
+    // POINT EMPTY
+    if (std::isnan(ordValues[0]) && std::isnan(ordValues[1])) {
+        return std::unique_ptr<Point>(factory.createPoint(hasZ ? 3 : 2));
+    }
+
     if (hasZ) {
         return std::unique_ptr<Point>(factory.createPoint(Coordinate(ordValues[0], ordValues[1], ordValues[2])));
     }
@@ -318,6 +324,10 @@ WKBReader::readPolygon()
     cout << "WKB numRings: " << numRings << endl;
 #endif
 
+    if(numRings == 0) {
+        return factory.createPolygon(hasZ ? 3 : 2);
+    }
+
     std::unique_ptr<LinearRing> shell;
     if(numRings > 0) {
         shell = readLinearRing();
diff --git a/tests/unit/io/WKBReaderTest.cpp b/tests/unit/io/WKBReaderTest.cpp
index 82cd14d..5e2f2e9 100644
--- a/tests/unit/io/WKBReaderTest.cpp
+++ b/tests/unit/io/WKBReaderTest.cpp
@@ -52,6 +52,14 @@ struct test_wkbreader_data {
         wktreader(gf.get())
     {}
 
+    GeomPtr
+    readHex(const std::string& hexwkb)
+    {
+        std::stringstream hexin(hexwkb);
+        GeomPtr g(wkbreader.readHEX(hexin));
+        return g;
+    }
+
     void
     testInput(const std::string& hexwkb,
               const std::string& expected)
@@ -524,5 +532,46 @@ void object::test<23>
 
 }
 
+// EMPTY WKB TESTS
+template<>
+template<>
+void object::test<24>
+()
+{
+    GeomPtr g;
+
+    // POINT EMPTY
+    g = readHex(std::string("0101000000000000000000F87F000000000000F87F"));
+    ensure_equals("POINT EMPTY isEmpty", g->isEmpty(), 1);
+    ensure_equals("POINT EMPTY getCoordinateDimension", g->getCoordinateDimension(), 2);
+
+    // POINT Z EMPTY
+    g = readHex(std::string("0101000080000000000000F87F000000000000F87F000000000000F87F"));
+    ensure_equals("POINT Z EMPTY isEmpty", g->isEmpty(), 1);
+    ensure_equals("POINT Z EMPTY getCoordinateDimension", g->getCoordinateDimension(), 3);
+
+    // LINESTRING EMPTY
+    g = readHex(std::string("010200000000000000"));
+    ensure_equals("LINESTRING EMPTY isEmpty", g->isEmpty(), 1);
+    ensure_equals("LINESTRING EMPTY getCoordinateDimension", g->getCoordinateDimension(), 2);
+
+    // LINESTRING Z EMPTY
+    g = readHex(std::string("010200008000000000"));
+    ensure_equals("LINESTRING Z EMPTY isEmpty", g->isEmpty(), 1);
+    ensure_equals("LINESTRING Z EMPTY getCoordinateDimension", g->getCoordinateDimension(), 3);
+
+    // POLYGON EMPTY
+    g = readHex(std::string("010300000000000000"));
+    ensure_equals("POLYGON EMPTY isEmpty", g->isEmpty(), 1);
+    ensure_equals("POLYGON EMPTY getCoordinateDimension", g->getCoordinateDimension(), 2);
+
+    // POLYGON Z EMPTY
+    g = readHex(std::string("010300008000000000"));
+    ensure_equals("POLYGON Z EMPTY isEmpty", g->isEmpty(), 1);
+    ensure_equals("POLYGON Z EMPTY getCoordinateDimension", g->getCoordinateDimension(), 3);
+
+}
+
+
 } // namespace tut
 

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

Summary of changes:
 .gitignore                      |  1 +
 src/geom/Point.cpp              |  1 +
 src/io/WKBReader.cpp            | 10 +++++++++
 tests/unit/io/WKBReaderTest.cpp | 49 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 61 insertions(+)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list