[geos-commits] r4308 - in trunk: src/io tests/unit/io

Sandro Santilli strk at kbt.io
Thu Dec 1 06:50:01 PST 2016


Author: strk
Date: 2016-12-01 06:50:01 -0800 (Thu, 01 Dec 2016)
New Revision: 4308

Modified:
   trunk/src/io/WKBWriter.cpp
   trunk/tests/unit/io/WKBWriterTest.cpp
Log:
Fixed WKB representation of empty polygon.

Patch by Sergey Fedoseev
Closes #680.

Modified: trunk/src/io/WKBWriter.cpp
===================================================================
--- trunk/src/io/WKBWriter.cpp	2016-11-22 10:49:34 UTC (rev 4307)
+++ trunk/src/io/WKBWriter.cpp	2016-12-01 14:50:01 UTC (rev 4308)
@@ -163,6 +163,11 @@
 	
 	writeGeometryType(WKBConstants::wkbPolygon, g.getSRID());
 	writeSRID(g.getSRID());
+
+	if (g.isEmpty()) {
+		writeInt(0);
+		return;
+	}
 	
 	std::size_t nholes = g.getNumInteriorRing();
 	writeInt(nholes+1);

Modified: trunk/tests/unit/io/WKBWriterTest.cpp
===================================================================
--- trunk/tests/unit/io/WKBWriterTest.cpp	2016-11-22 10:49:34 UTC (rev 4307)
+++ trunk/tests/unit/io/WKBWriterTest.cpp	2016-12-01 14:50:01 UTC (rev 4308)
@@ -159,6 +159,30 @@
 
   }
 
+    // 5 - Check WKB representation of empty polygon
+    // See http://trac.osgeo.org/geos/ticket/680
+    template<>
+    template<>
+    void object::test<5>()
+    {
+        geos::geom::Geometry *geom = wktreader.read("POLYGON 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, "0103000020E610000000000000" );
+
+        geos::geom::Geometry *geom2 = wkbreader.readHEX(result_stream);
+        assert( geom->equals(geom2) );
+
+        delete geom;
+        delete geom2;
+    }
+
 } // namespace tut
 



More information about the geos-commits mailing list