[mapguide-commits] r9219 - in sandbox/jng/geoprocessing: Common/Geometry Common/PlatformBase/Services Server/src/UnitTesting

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Jun 23 04:58:50 PDT 2017


Author: jng
Date: 2017-06-23 04:58:50 -0700 (Fri, 23 Jun 2017)
New Revision: 9219

Modified:
   sandbox/jng/geoprocessing/Common/Geometry/Geometry.cpp
   sandbox/jng/geoprocessing/Common/Geometry/Geometry.h
   sandbox/jng/geoprocessing/Common/PlatformBase/Services/GeoJsonWriter.cpp
   sandbox/jng/geoprocessing/Server/src/UnitTesting/TestGeometry.cpp
   sandbox/jng/geoprocessing/Server/src/UnitTesting/TestGeometry.h
Log:
Add Tessellate() to MgGeometry. This calls into MgSpatialUtility::TesellateCurves() and allows for curve-based geometry to be approximated to line strings.

The MgGeoJsonWriter has been updated to auto-tessellate curve geometries allowing for the to be output in GeoJSON in approximated form (as opposed to being null)

Unit tests added to verify that writing out curve geometries in GeoJSON does not produce "geometry: null" due to auto-tessellation.

Modified: sandbox/jng/geoprocessing/Common/Geometry/Geometry.cpp
===================================================================
--- sandbox/jng/geoprocessing/Common/Geometry/Geometry.cpp	2017-06-21 15:53:47 UTC (rev 9218)
+++ sandbox/jng/geoprocessing/Common/Geometry/Geometry.cpp	2017-06-23 11:58:50 UTC (rev 9219)
@@ -263,4 +263,9 @@
 MgPreparedGeometry* MgGeometry::Prepare()
 {
     return MgPreparedGeometry::Create(this);
+}
+
+MgGeometry* MgGeometry::Tessellate()
+{
+    return MgSpatialUtility::TesselateCurve(this);
 }
\ No newline at end of file

Modified: sandbox/jng/geoprocessing/Common/Geometry/Geometry.h
===================================================================
--- sandbox/jng/geoprocessing/Common/Geometry/Geometry.h	2017-06-21 15:53:47 UTC (rev 9218)
+++ sandbox/jng/geoprocessing/Common/Geometry/Geometry.h	2017-06-23 11:58:50 UTC (rev 9219)
@@ -750,11 +750,38 @@
     /// virtual MgGeometry Prepare();
     /// \htmlinclude SyntaxBottom.html
     ///
+    /// \since 3.3
+    ///
     /// \return
     /// An MgPreparedGeometry representing the prepared version of this geometry
     ///
     MgPreparedGeometry* Prepare();
 
+    ///////////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Returns a tessellated version of this geometry. A tessellated version of this
+    /// geometry will have all arc/curve geometry components approximated with line
+    /// strings. Thus, this method is only applicable for curve geometries and has
+    /// no effect on non-curve geometries.
+    ///
+    /// <!-- Syntax in .Net, Java, and PHP -->
+    /// \htmlinclude DotNetSyntaxTop.html
+    /// virtual MgGeometry Prepare();
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude JavaSyntaxTop.html
+    /// virtual MgGeometry Prepare();
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude PHPSyntaxTop.html
+    /// virtual MgGeometry Prepare();
+    /// \htmlinclude SyntaxBottom.html
+    ///
+    /// \since 3.3
+    ///
+    /// \return
+    /// A tesellated version of this geometry. If this geometry is not curve-based, the operation does nothing and this method returns itself.
+    ///
+    MgGeometry* Tessellate();
+
 INTERNAL_API:
 
     virtual INT32 GetEntityType();

Modified: sandbox/jng/geoprocessing/Common/PlatformBase/Services/GeoJsonWriter.cpp
===================================================================
--- sandbox/jng/geoprocessing/Common/PlatformBase/Services/GeoJsonWriter.cpp	2017-06-21 15:53:47 UTC (rev 9218)
+++ sandbox/jng/geoprocessing/Common/PlatformBase/Services/GeoJsonWriter.cpp	2017-06-23 11:58:50 UTC (rev 9219)
@@ -36,7 +36,7 @@
 
     MG_TRY()
 
-        CHECKARGUMENTNULL(reader, L"MgGeoJsonWriter.FeatureToGeoJson");
+    CHECKARGUMENTNULL(reader, L"MgGeoJsonWriter.FeatureToGeoJson");
 
     if (!idPropertyName.empty())
         idIndex = reader->GetPropertyIndex(idPropertyName);
@@ -67,7 +67,9 @@
                 geom = m_agfRw->Read(agf, transform);
             else
                 geom = m_agfRw->Read(agf);
-            ToGeoJson(geom, geomVal);
+            
+            Ptr<MgGeometry> g = geom->Tessellate();
+            ToGeoJson(g, geomVal);
         }
         catch (MgException* ex)
         {
@@ -97,7 +99,9 @@
                             geom = m_agfRw->Read(agf, transform);
                         else
                             geom = m_agfRw->Read(agf);
-                        ToGeoJson(geom, geomVal);
+
+                        Ptr<MgGeometry> g = geom->Tessellate();
+                        ToGeoJson(g, geomVal);
                     }
                     catch (MgException* ex)
                     {
@@ -175,7 +179,8 @@
     ret += L"\"properties\": {}, "; //PROPERTIES
     
     STRING geomVal;
-    ToGeoJson(geom, geomVal);
+    Ptr<MgGeometry> g = geom->Tessellate();
+    ToGeoJson(g, geomVal);
     ret += geomVal; //GEOMETRY
 
     ret += L"}"; //END FEATURE

Modified: sandbox/jng/geoprocessing/Server/src/UnitTesting/TestGeometry.cpp
===================================================================
--- sandbox/jng/geoprocessing/Server/src/UnitTesting/TestGeometry.cpp	2017-06-21 15:53:47 UTC (rev 9218)
+++ sandbox/jng/geoprocessing/Server/src/UnitTesting/TestGeometry.cpp	2017-06-23 11:58:50 UTC (rev 9219)
@@ -2961,4 +2961,100 @@
     {
         throw;
     }
+}
+
+void TestGeometry::TestCase_CurvePolygon_AsGeoJSON()
+{
+    try
+    {
+        Ptr<MgWktReaderWriter> wktRw = new MgWktReaderWriter();
+        Ptr<MgGeometry> geom = wktRw->Read(L"CURVEPOLYGON ((0 0 (LINESTRINGSEGMENT (10 10, 10 20, 20 20), ARC (20 15, 10 10))), (0 0 (ARC (11 11, 12 12), LINESTRINGSEGMENT (10 10, 20 20, 40 40, 90 90))))");
+
+        Ptr<MgGeoJsonWriter> gw = new MgGeoJsonWriter();
+        STRING geoJson = gw->GeometryToGeoJson(geom);
+
+        CPPUNIT_ASSERT(geoJson.find(L"geometry\": null") == STRING::npos);
+    }
+    catch (MgException* e)
+    {
+        STRING message = e->GetDetails(TEST_LOCALE);
+        SAFE_RELEASE(e);
+        CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+    }
+    catch (...)
+    {
+        throw;
+    }
+}
+
+void TestGeometry::TestCase_CurveString_AsGeoJSON()
+{
+    try
+    {
+        Ptr<MgWktReaderWriter> wktRw = new MgWktReaderWriter();
+        Ptr<MgGeometry> geom = wktRw->Read(L"CURVESTRING (0 0 (CIRCULARARCSEGMENT (11 11, 12 12), LINESTRINGSEGMENT (10 10, 20 20, 30 40)))");
+
+        Ptr<MgGeoJsonWriter> gw = new MgGeoJsonWriter();
+        STRING geoJson = gw->GeometryToGeoJson(geom);
+
+        CPPUNIT_ASSERT(geoJson.find(L"geometry\": null") == STRING::npos);
+    }
+    catch (MgException* e)
+    {
+        STRING message = e->GetDetails(TEST_LOCALE);
+        SAFE_RELEASE(e);
+        CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+    }
+    catch (...)
+    {
+        throw;
+    }
+}
+
+void TestGeometry::TestCase_MultiCurvePolygon_AsGeoJSON()
+{
+    try
+    {
+        Ptr<MgWktReaderWriter> wktRw = new MgWktReaderWriter();
+        Ptr<MgGeometry> geom = wktRw->Read(L"MULTICURVEPOLYGON (((0 0 (LINESTRINGSEGMENT (10 10, 10 20, 20 20), ARC (20 15, 10 10))), (0 0 (ARC (11 11, 12 12), LINESTRINGSEGMENT (10 10, 20 20, 40 40, 90 90)))),((0 0 (LINESTRINGSEGMENT (10 10, 10 20, 20 20), ARC (20 15, 10 10))), (0 0 (ARC (11 11, 12 12), LINESTRINGSEGMENT (10 10, 20 20, 40 40, 90 90)))))");
+
+        Ptr<MgGeoJsonWriter> gw = new MgGeoJsonWriter();
+        STRING geoJson = gw->GeometryToGeoJson(geom);
+
+        CPPUNIT_ASSERT(geoJson.find(L"geometry\": null") == STRING::npos);
+    }
+    catch (MgException* e)
+    {
+        STRING message = e->GetDetails(TEST_LOCALE);
+        SAFE_RELEASE(e);
+        CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+    }
+    catch (...)
+    {
+        throw;
+    }
+}
+
+void TestGeometry::TestCase_MultiCurveString_AsGeoJSON()
+{
+    try
+    {
+        Ptr<MgWktReaderWriter> wktRw = new MgWktReaderWriter();
+        Ptr<MgGeometry> geom = wktRw->Read(L"MULTICURVESTRING ((0 0 (LINESTRINGSEGMENT (10 10, 20 20, 30 40))),(0 0 (ARC (11 11, 12 12), LINESTRINGSEGMENT (10 10, 20 20, 30 40))))");
+
+        Ptr<MgGeoJsonWriter> gw = new MgGeoJsonWriter();
+        STRING geoJson = gw->GeometryToGeoJson(geom);
+
+        CPPUNIT_ASSERT(geoJson.find(L"geometry\": null") == STRING::npos);
+    }
+    catch (MgException* e)
+    {
+        STRING message = e->GetDetails(TEST_LOCALE);
+        SAFE_RELEASE(e);
+        CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+    }
+    catch (...)
+    {
+        throw;
+    }
 }
\ No newline at end of file

Modified: sandbox/jng/geoprocessing/Server/src/UnitTesting/TestGeometry.h
===================================================================
--- sandbox/jng/geoprocessing/Server/src/UnitTesting/TestGeometry.h	2017-06-21 15:53:47 UTC (rev 9218)
+++ sandbox/jng/geoprocessing/Server/src/UnitTesting/TestGeometry.h	2017-06-23 11:58:50 UTC (rev 9219)
@@ -70,6 +70,11 @@
     CPPUNIT_TEST(TestCase_Simplify_DP);
     CPPUNIT_TEST(TestCase_Simplify_TP);
 
+    CPPUNIT_TEST(TestCase_CurveString_AsGeoJSON);
+    CPPUNIT_TEST(TestCase_CurvePolygon_AsGeoJSON);
+    CPPUNIT_TEST(TestCase_MultiCurvePolygon_AsGeoJSON);
+    CPPUNIT_TEST(TestCase_MultiCurveString_AsGeoJSON);
+
 #ifdef TEST_PREPARED_GEOMETRY_PERF
     CPPUNIT_TEST(TestCase_PreparedGeometryPerformance);
 #endif
@@ -122,6 +127,11 @@
     void TestCase_Simplify_DP();
     void TestCase_Simplify_TP();
 
+    void TestCase_CurveString_AsGeoJSON();
+    void TestCase_CurvePolygon_AsGeoJSON();
+    void TestCase_MultiCurvePolygon_AsGeoJSON();
+    void TestCase_MultiCurveString_AsGeoJSON();
+
     void TestCase_PreparedGeometryPerformance();
 
     MgPoint*             CreatePoint();



More information about the mapguide-commits mailing list