[mapguide-commits] r9616 - in sandbox/jng/mvt_alt: Common/Stylization Server/src/UnitTesting

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sat Sep 21 18:30:42 PDT 2019


Author: jng
Date: 2019-09-21 18:30:41 -0700 (Sat, 21 Sep 2019)
New Revision: 9616

Modified:
   sandbox/jng/mvt_alt/Common/Stylization/LineBuffer.cpp
   sandbox/jng/mvt_alt/Server/src/UnitTesting/TestMisc.cpp
Log:
It turns out that LineBuffer does actually support homogeneous multi-geometries. There is a NewGeometry() API that supposedly delineates the start of a new geometry within a LineBuffer (commentary around this method says as such), but this is never actually called from LoadFromAgf() (which the method commentary around this method also claim to be called by).

This updates LoadFromAgf() to ensure NewGeometry() is called at the start of every geometry loop iteration beyond the first and the conversion test has been updated to roundtrip back out to LineBuffer -> MgGeometry -> WKT to compare against the original and verify that it is the same as the original source WKT.

Modified: sandbox/jng/mvt_alt/Common/Stylization/LineBuffer.cpp
===================================================================
--- sandbox/jng/mvt_alt/Common/Stylization/LineBuffer.cpp	2019-09-22 00:40:57 UTC (rev 9615)
+++ sandbox/jng/mvt_alt/Common/Stylization/LineBuffer.cpp	2019-09-22 01:30:41 UTC (rev 9616)
@@ -901,6 +901,10 @@
 
             for (int q=0; q<num_geoms; ++q)
             {
+                // Mark the beginning of a new geometry
+                if (q > 0)
+                    NewGeometry();
+
                 // skip past geometry type of subgeometry
                 // we know it is LineString or Polygon or Point respectively
                 if (is_multi)

Modified: sandbox/jng/mvt_alt/Server/src/UnitTesting/TestMisc.cpp
===================================================================
--- sandbox/jng/mvt_alt/Server/src/UnitTesting/TestMisc.cpp	2019-09-22 00:40:57 UTC (rev 9615)
+++ sandbox/jng/mvt_alt/Server/src/UnitTesting/TestMisc.cpp	2019-09-22 01:30:41 UTC (rev 9616)
@@ -24,6 +24,7 @@
 #include "FoundationDefs.h"
 #include "FdoConnectionManager.h"
 #include "LineBuffer.h"
+#include "RS_BufferOutputStream.h"
 
 const STRING TEST_LOCALE = L"en";
 static const INT32 MG_TEST_THREADS = 16;
@@ -929,8 +930,10 @@
         Ptr<MgGeometry> gMultiLineString = wktRw.Read(L"MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))");
         Ptr<MgGeometry> gPolygon1 = wktRw.Read(L"POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))");
         Ptr<MgGeometry> gPolygon2 = wktRw.Read(L"POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10), (20 30, 35 35, 30 20, 20 30))");
-        Ptr<MgGeometry> gMultiPolygon1 = wktRw.Read(L"MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))");
-        Ptr<MgGeometry> gMultiPolygon2 = wktRw.Read(L"MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))");
+        STRING mpWkt1 = L"MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))";
+        Ptr<MgGeometry> gMultiPolygon1 = wktRw.Read(mpWkt1);
+        STRING mpWkt2 = L"MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))";
+        Ptr<MgGeometry> gMultiPolygon2 = wktRw.Read(mpWkt2);
 
         //Point
         {
@@ -954,7 +957,7 @@
             Ptr<MgByte> bytes = agfSink->ToBuffer();
             lb.LoadFromAgf(bytes->Bytes(), bytes->GetLength(), nullptr);
 
-            CPPUNIT_ASSERT(1 == lb.geom_count()); //LineBuffer flattens this
+            CPPUNIT_ASSERT(4 == lb.geom_count());
             CPPUNIT_ASSERT(4 == lb.point_count());
             CPPUNIT_ASSERT(10 == lb.x_coord(0));
             CPPUNIT_ASSERT(40 == lb.y_coord(0));
@@ -1010,7 +1013,7 @@
             Ptr<MgByte> bytes = agfSink->ToBuffer();
             lb.LoadFromAgf(bytes->Bytes(), bytes->GetLength(), nullptr);
 
-            CPPUNIT_ASSERT(1 == lb.geom_count()); //LineBuffer flattens this
+            CPPUNIT_ASSERT(2 == lb.geom_count());
             CPPUNIT_ASSERT(2 == lb.cntr_count());
             CPPUNIT_ASSERT(3 == lb.cntr_size(0));
             CPPUNIT_ASSERT(4 == lb.cntr_size(1));
@@ -1201,7 +1204,7 @@
             Ptr<MgByte> bytes = agfSink->ToBuffer();
             lb.LoadFromAgf(bytes->Bytes(), bytes->GetLength(), nullptr);
 
-            CPPUNIT_ASSERT(1 == lb.geom_count()); //LineBuffer flattens this
+            CPPUNIT_ASSERT(2 == lb.geom_count());
             auto cc = lb.cntr_count();
             CPPUNIT_ASSERT(2 == cc);
             auto closed1 = lb.contour_closed(0);
@@ -1270,6 +1273,17 @@
                     }
                 }
             }
+
+            RS_BufferOutputStream ros(bytes->GetLength());
+            lb.ToAgf(&ros);
+
+            Ptr<MgByte> obs = new MgByte(ros.data(), ros.length());
+            Ptr<MgByteSource> bs = new MgByteSource(obs);
+            Ptr<MgByteReader> oagf = bs->GetReader();
+
+            Ptr<MgGeometry> g2 = agfRw.Read(oagf);
+            STRING owkt = wktRw.Write(g2);
+            CPPUNIT_ASSERT(owkt == mpWkt1);
         }
 
         //MultiPolygon 2
@@ -1280,7 +1294,7 @@
             Ptr<MgByte> bytes = agfSink->ToBuffer();
             lb.LoadFromAgf(bytes->Bytes(), bytes->GetLength(), nullptr);
 
-            CPPUNIT_ASSERT(1 == lb.geom_count()); //LineBuffer flattens this
+            CPPUNIT_ASSERT(2 == lb.geom_count());
             auto cc = lb.cntr_count();
             CPPUNIT_ASSERT(3 == cc);
             auto closed1 = lb.contour_closed(0);
@@ -1386,6 +1400,17 @@
                     }
                 }
             }
+
+            RS_BufferOutputStream ros(bytes->GetLength());
+            lb.ToAgf(&ros);
+            
+            Ptr<MgByte> obs = new MgByte(ros.data(), ros.length());
+            Ptr<MgByteSource> bs = new MgByteSource(obs);
+            Ptr<MgByteReader> oagf = bs->GetReader();
+
+            Ptr<MgGeometry> g2 = agfRw.Read(oagf);
+            STRING owkt = wktRw.Write(g2);
+            CPPUNIT_ASSERT(owkt == mpWkt2);
         }
     }
     catch (MgException* e)



More information about the mapguide-commits mailing list