[mapguide-commits] r1139 - trunk/MgDev/Server/src/Services/Feature

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Feb 27 22:22:28 EST 2007


Author: tonyfang
Date: 2007-02-27 22:22:27 -0500 (Tue, 27 Feb 2007)
New Revision: 1139

Modified:
   trunk/MgDev/Server/src/Services/Feature/ServerGetSpatialContexts.cpp
Log:
MapGuide RFC 6 Overriding Coordinate Systems in Feature Sources
- GetSpatialContexts to always use overrides (instead of only when spatial context is undefined)
- Also for SHP files with no prj, return the "Default" empty spatial context (i.e., remove the workaround)

Modified: trunk/MgDev/Server/src/Services/Feature/ServerGetSpatialContexts.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerGetSpatialContexts.cpp	2007-02-27 20:01:35 UTC (rev 1138)
+++ trunk/MgDev/Server/src/Services/Feature/ServerGetSpatialContexts.cpp	2007-02-28 03:22:27 UTC (rev 1139)
@@ -94,33 +94,15 @@
             Ptr<MgSpatialContextData> spatialData = GetSpatialContextData(spatialReader);
             CHECKNULL((MgSpatialContextData*)spatialData, L"MgServerGetSpatialContexts.GetSpatialContexts");
 
-            // TODO: Remove this workaround for the SHP FDO provider when the defect 
-            // for the "Default" active spatial contexts being blank is fixed.
-            // START WORKAROUND CODE
-            bool bAddSpatialContext = true;
+            // Add spatial data to the spatialcontext reader
+            mgSpatialContextReader->AddSpatialData(spatialData);
 
-            STRING name = spatialData->GetName();
-            STRING coordSys = spatialData->GetCoordinateSystem();
-            STRING coordSyswkt = spatialData->GetCoordinateSystemWkt();
-            if((name == L"Default") && (coordSys.empty()) && (coordSyswkt.empty()))
+            // If only active spatial context is required skip all others
+            if (bActiveOnly)
             {
-                // The "Default" coordinate system WKT is empty so we want to skip this one
-                bAddSpatialContext = false;
+                if (spatialReader->IsActive())
+                    break;
             }
-            // END WORKAROUND CODE
-
-            if(bAddSpatialContext)
-            {
-                // Add spatial data to the spatialcontext reader
-                mgSpatialContextReader->AddSpatialData(spatialData);
-
-                // If only active spatial context is required skip all others
-                if (bActiveOnly)
-                {
-                    if (spatialReader->IsActive())
-                        break;
-                }
-            }
         }
 
         featureServiceCache->AddSpatialContext(resId, bActiveOnly, mgSpatialContextReader);
@@ -140,36 +122,67 @@
     CHECKNULL((FdoString*)name, L"MgServerGetSpatialContexts.GetSpatialContexts");
     spatialData->SetName(STRING(name));
 
-    // Co-ordinate system
     FdoString* csName = spatialReader->GetCoordinateSystem();
-    if (csName != NULL)
+    STRING coordSysName = STRING(csName);
+    bool spatialContextDefined = !coordSysName.empty();
+    bool coordSysOverridden = false;
+
+    // look for coordinate system override
+    if (m_spatialContextInfoMap.get() != NULL)
     {
-        if (wcslen(csName) <= 0)
+        // Perform substitution of missing coordinate system with
+        // the spatial context mapping defined in feature source document
+        std::map<STRING, STRING>::const_iterator iter;
+        iter = m_spatialContextInfoMap->find(name);
+        if (iter != m_spatialContextInfoMap->end())
         {
-            if (m_spatialContextInfoMap.get() != NULL)
-            {
-                // Perform substitution of missing coordinate system with
-                // the spatial context mapping defined in feature source document
-                std::map<STRING, STRING>::const_iterator iter;
-                iter = m_spatialContextInfoMap->find(name);
-                if (iter != m_spatialContextInfoMap->end())
-                {
-                    csName = (iter->second).c_str();
-                }
-            }
+            csName = (iter->second).c_str();
+            coordSysOverridden = true;
         }
+    }
+
+    if (csName != NULL)
+    {
         spatialData->SetCoordinateSystem(STRING(csName));
     }
 
     // WKT for co-ordinate system
-    FdoString* csWkt = spatialReader->GetCoordinateSystemWkt();
-    if (csWkt != NULL)
+    FdoString* csWkt = NULL;
+    STRING srsWkt = L"";
+
+    // Desc for spatial context
+    STRING desc = L"";
+
+    // Extent type
+    FdoSpatialContextExtentType extentType = FdoSpatialContextExtentType_Dynamic; // or should it be initialized to static?
+
+    // Extent (Geometry data)
+    FdoPtr<FdoByteArray> byteArray = NULL;
+
+    // XY Tolerance
+    double xyTol = 0;
+
+    // Z Tolerance
+    double zTol = 0;
+
+    // Whether it is active or not
+    bool isActive = spatialReader->IsActive();
+
+    if (coordSysOverridden)
     {
-        // This is a work around for MG298: WKT not set for WMS and 
-        // WFS spatial contexts.
-        STRING srsWkt = csWkt;
+        srsWkt = csName;
+        desc = L"This coordinate system has been overridden.";
+    }
+    else if (spatialContextDefined && !coordSysOverridden)
+    {
+        csWkt = spatialReader->GetCoordinateSystemWkt();
+        srsWkt = csWkt;
+
         if (srsWkt.empty())
         {
+            // This is a work around for MG298: WKT not set for WMS and 
+            // WFS spatial contexts.
+
             try
             {
                 Ptr<MgCoordinateSystem> csPtr = new MgCoordinateSystem();
@@ -183,29 +196,22 @@
             {
                 // Just use the empty WKT. 
             }
-
-            spatialData->SetCoordinateSystemWkt(srsWkt);
         }
-        else
-        {
-            spatialData->SetCoordinateSystemWkt(STRING(csWkt));
-        }
-    }
 
-    // Desc for spatial context
-    FdoString* desc = spatialReader->GetDescription();
-    if (desc != NULL)
-    {
-        spatialData->SetDescription(STRING(desc));
+        FdoString* fdoDesc = spatialReader->GetDescription();
+        desc = STRING(fdoDesc);
+
+        // retrieve other values from spatialReader
+        extentType = spatialReader->GetExtentType();
+        byteArray = spatialReader->GetExtent();
+        xyTol = spatialReader->GetXYTolerance();
+        zTol = spatialReader->GetZTolerance();
     }
 
-    // Extent type
-    FdoSpatialContextExtentType extentType = spatialReader->GetExtentType();
+    spatialData->SetCoordinateSystemWkt(srsWkt);
+    spatialData->SetDescription(desc);
     spatialData->SetExtentType((INT32)extentType);
 
-    // Extent (Geometry data)
-    FdoPtr<FdoByteArray> byteArray = spatialReader->GetExtent();
-
     if (byteArray.p != NULL)
     {
         INT32 size = (INT32)byteArray->GetCount();
@@ -215,15 +221,12 @@
     }
 
     // XY Tolerance
-    double xyTol = spatialReader->GetXYTolerance();
     spatialData->SetXYTolerance(xyTol);
 
     // Z Tolerance
-    double zTol = spatialReader->GetZTolerance();
-    spatialData->SetXYTolerance(zTol);
+    spatialData->SetZTolerance(zTol);
 
     // Whether it is active or not
-    bool isActive = spatialReader->IsActive();
     spatialData->SetActiveStatus(isActive);
 
     return spatialData.Detach();



More information about the mapguide-commits mailing list