[geos-commits] [SCM] GEOS branch master updated. 466cff135c8e504632ae38b79a1348dbadb390f1
git at osgeo.org
git at osgeo.org
Tue Aug 11 12:47:32 PDT 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 466cff135c8e504632ae38b79a1348dbadb390f1 (commit)
from 2a2e67ff4400adc9041e21eb0031c51f8f4d2487 (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 466cff135c8e504632ae38b79a1348dbadb390f1
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Tue Aug 11 12:20:36 2020 -0700
Output POINT EMPTY in WKB. References #1005
diff --git a/include/geos/io/WKBWriter.h b/include/geos/io/WKBWriter.h
index 4bbadf0..d40e281 100644
--- a/include/geos/io/WKBWriter.h
+++ b/include/geos/io/WKBWriter.h
@@ -184,6 +184,7 @@ private:
unsigned char buf[8];
void writePoint(const geom::Point& p);
+ void writePointEmpty(const geom::Point& p);
// throws IOException
void writeLineString(const geom::LineString& ls);
diff --git a/src/io/WKBWriter.cpp b/src/io/WKBWriter.cpp
index 7876383..37babfd 100644
--- a/src/io/WKBWriter.cpp
+++ b/src/io/WKBWriter.cpp
@@ -30,6 +30,7 @@
#include <geos/geom/MultiLineString.h>
#include <geos/geom/MultiPolygon.h>
#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/CoordinateArraySequence.h>
#include <geos/geom/PrecisionModel.h>
#include <ostream>
@@ -121,10 +122,25 @@ WKBWriter::write(const Geometry& g, ostream& os)
}
void
+WKBWriter::writePointEmpty(const Point& g)
+{
+ writeByteOrder();
+ writeGeometryType(WKBConstants::wkbPoint, g.getSRID());
+ writeSRID(g.getSRID());
+
+ Coordinate c(DoubleNotANumber, DoubleNotANumber, DoubleNotANumber);
+ CoordinateArraySequence cas(std::size_t(1), g.getCoordinateDimension());
+ cas.setAt(c, 0);
+
+ writeCoordinateSequence(cas, false);
+}
+
+void
WKBWriter::writePoint(const Point& g)
{
- if(g.isEmpty()) throw
- util::IllegalArgumentException("Empty Points cannot be represented in WKB");
+ if(g.isEmpty()) {
+ return writePointEmpty(g);
+ }
writeByteOrder();
diff --git a/tests/unit/io/WKBWriterTest.cpp b/tests/unit/io/WKBWriterTest.cpp
index bf29c88..381449c 100644
--- a/tests/unit/io/WKBWriterTest.cpp
+++ b/tests/unit/io/WKBWriterTest.cpp
@@ -173,5 +173,30 @@ void object::test<5>
assert(geom->equals(geom2.get()));
}
+
+// 5 - Check WKB representation of empty polygon
+// See http://trac.osgeo.org/geos/ticket/680
+template<>
+template<>
+void object::test<6>
+()
+{
+ auto geom = wktreader.read("POINT EMPTY");
+ geom->setSRID(4326);
+ std::stringstream result_stream;
+
+ wkbwriter.setOutputDimension(2);
+ wkbwriter.setByteOrder(1);
+ wkbwriter.setIncludeSRID(1);
+ wkbwriter.writeHEX(*geom, result_stream);
+
+ std::string actual = result_stream.str();
+ ensure_equals(actual, "0101000020E6100000000000000000F87F000000000000F87F");
+
+ auto geom2 = wkbreader.readHEX(result_stream);
+ assert(geom->equals(geom2.get()));
+}
+
+
} // namespace tut
-----------------------------------------------------------------------
Summary of changes:
include/geos/io/WKBWriter.h | 1 +
src/io/WKBWriter.cpp | 20 ++++++++++++++++++--
tests/unit/io/WKBWriterTest.cpp | 25 +++++++++++++++++++++++++
3 files changed, 44 insertions(+), 2 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list