[mapguide-commits] r5247 - trunk/MgDev/Common/CoordinateSystem

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Oct 5 13:57:37 EDT 2010


Author: NormOlsen
Date: 2010-10-05 17:57:37 +0000 (Tue, 05 Oct 2010)
New Revision: 5247

Modified:
   trunk/MgDev/Common/CoordinateSystem/CoordSysDatumDictionary.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysDictionary.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysEllipsoidDictionary.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysGeodeticTransformDef.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysGeodeticTransformation.cpp
   trunk/MgDev/Common/CoordinateSystem/MentorUtil.cpp
Log:
RFC 98 -- Implement the concept of a Null Geodetic Transformation to replace the concept of a Molodensky with zero translations.

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysDatumDictionary.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysDatumDictionary.cpp	2010-10-05 15:46:37 UTC (rev 5246)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysDatumDictionary.cpp	2010-10-05 17:57:37 UTC (rev 5247)
@@ -50,10 +50,7 @@
 #undef cs_Dtdef07_
 #undef cs_Dtdef08_
 
-
-//FIXME (CS_rlsUodt.c isn't built anymore)
 //Externs from Mentor
-/*
 extern "C"
 {
     int CSdtrupReadOld (csFILE *oldStrm,struct csDtrup_ *dtrup,int old_lvl);
@@ -61,13 +58,11 @@
     int CSdtrupRead06 (csFILE *oldStrm,struct csDtrup_ *dtrup);
     extern char cs_Dir[];
 }
-*/
 
-//FIXME (CS_rlsUodt.c isn't built anymore)
+
 //Function which works like CS_dtrd(), except that it reads version
 //5 datum structs.
 //
-/*
 static int
 CS_dtrd05(
     csFILE *oldStrm,
@@ -106,8 +101,8 @@
     }
     return nStatus;
 }
-*/
 
+
 //Function which returns whether the specified "magic number" is
 //a valid one for a Mentor datum dictionary.  The returned value
 //indicates the highest access level allowed:  CsDictionaryOpenMode::Write if current
@@ -254,11 +249,9 @@
 
     throw new MgInvalidOperationException(L"CCoordinateSystemDatumDictionary.dtdef", __LINE__, __WFILE__, NULL, L"", NULL);
 
-    //FIXME (CS_rlsUodt.c isn't built anymore)
-    //
     //It's an old version.  We need to do a special search
     //in the file, and then, if found, update it to a current struct.
-    /*
+    
     UINT32 nStructSize, nNameSize;
     GetDatumSizeInfo(m_lMagic, nStructSize, nNameSize);
     if (strlen(kpName) > nNameSize-1) return NULL;
@@ -308,7 +301,6 @@
     }
     CS_fclose(pFile);
     return pDef;
-    */
 }
 
 //-------------------------------------------------------------------------------
@@ -657,12 +649,11 @@
         assert(nVersion > 0);
         switch (nVersion)
         {
-        // FIXME (CS_rlsUpdt.c isn't built anymore)
-            /*
         case 5:
             //Generate summary for version 5 datum file.
             m_pmapSystemNameDescription = MentorDictionary::GenerateSystemNameDescriptionMap<cs_Dtdef05_>(
                 pFile,
+                DtKey05,
                 DtDesc05,
                 CS_dtrd05);
             break;
@@ -670,10 +661,10 @@
             //Generate summary for version 6 datum file.
             m_pmapSystemNameDescription = MentorDictionary::GenerateSystemNameDescriptionMap<cs_Dtdef06_>(
                 pFile,
+                DtKey06,
                 DtDesc06,
                 CS_dtrd06);
-            break;
-            */
+            break;   
         case 7:
         case 8:
             //Generate summary for version 7 or 8 datum file.

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysDictionary.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysDictionary.cpp	2010-10-05 15:46:37 UTC (rev 5246)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysDictionary.cpp	2010-10-05 17:57:37 UTC (rev 5247)
@@ -49,25 +49,17 @@
 #undef cs_Csdef08_
 
 
-//FIXME (CS_rlsUodt.c isn't built anymore)
-//
 //Externs from Mentor
-/*
 extern "C"
 {
     int CScsrupReadOld (csFILE *oldStrm,struct csCsrup_ *csrup,int old_lvl);
     int CScsrupRead05 (csFILE *oldStrm,struct csCsrup_ *csrup);
     int CScsrupRead06 (csFILE *oldStrm,struct csCsrup_ *csrup);
 }
-*/
 
-
-//FIXME (CS_rlsUodt.c isn't built anymore)
-//
 //Function which works like CS_csrd(), except that it reads version
 //5 coordsys structs.
 //
-/*
 static int
 CS_csrd05(
     csFILE *oldStrm,
@@ -85,8 +77,6 @@
     return nStatus;
 }
 
-
-
 //Function which works like CS_csrd(), except that it reads version
 //6 coordsys structs.
 //
@@ -106,9 +96,7 @@
     }
     return nStatus;
 }
-*/
 
-
 //Function which returns whether the specified "magic number" is
 //a valid one for a Mentor coordsys dictionary.  The returned value
 //indicates the highest access level allowed:  CsDictionaryOpenMode::Write if current
@@ -268,12 +256,8 @@
 
     throw new MgInvalidOperationException(L"CCoordinateSystemDictionary.csdef", __LINE__, __WFILE__, NULL, L"", NULL);
 
-    //FIXME (CS_rlsUodt.c isn't built anymore)
-    //
-
     //It's an old version.  We need to do a special search
     //in the file, and then, if found, update it to a current struct.
-    /*
     UINT32 nStructSize, nNameSize;
     GetCoordinateSystemSizeInfo(m_lMagic, nStructSize, nNameSize);
     if (strlen(kpName) > nNameSize-1) return NULL;
@@ -334,7 +318,6 @@
     }
 
     return pDef;
-    */
 }
 
 //------------------------------------------------------------------------
@@ -681,12 +664,11 @@
         assert(nVersion > 0);
         switch (nVersion)
         {
-        //FIXME (CS_rlsUpdt.c isn't built anymore)
-            /*
         case 5:
             //Generate summary for version 5 coordsys file.
             m_pmapSystemNameDescription = MentorDictionary::GenerateSystemNameDescriptionMap<cs_Csdef05_>(
                 pFile,
+                CsKey05,
                 CsDesc05,
                 CS_csrd05);
             break;
@@ -694,10 +676,10 @@
             //Generate summary for version 6 coordsys file.
             m_pmapSystemNameDescription = MentorDictionary::GenerateSystemNameDescriptionMap<cs_Csdef06_>(
                 pFile,
+                CsKey06,
                 CsDesc06,
                 CS_csrd06);
             break;
-            */
         case 7:
         case 8:
             //Generate summary for version 7 or 8 coordsys file.

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysEllipsoidDictionary.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysEllipsoidDictionary.cpp	2010-10-05 15:46:37 UTC (rev 5246)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysEllipsoidDictionary.cpp	2010-10-05 17:57:37 UTC (rev 5247)
@@ -52,17 +52,12 @@
 
 
 
-//FIXME (CS_rlsUodt.c isn't built anymore)
 //Externs from Mentor
-/*
 extern "C"
 {
     int CSelrupReadOld (csFILE *oldStrm,struct csElrup_ *elrup,int old_lvl);
 }
-*/
 
-
-
 //Function which returns whether the specified "magic number" is
 //a valid one for a Mentor ellipsoid dictionary.  The returned value
 //indicates the highest access level allowed:  CsDictionaryOpenMode::Write if current
@@ -194,13 +189,9 @@
     }
 
     throw new MgInvalidOperationException(L"CCoordinateSystemEllipsoidDictionary.eldef", __LINE__, __WFILE__, NULL, L"", NULL);
-
-    //FIXME (CS_rlsUodt.c isn't built anymore)
-    //
+    
     //It's an old version.  We need to do a special search
-    //in the file, and then, if found, update it to a current struct.
-
-    /*
+    //in the file, and then, if found, update it to a current struct.    
     UINT32 nStructSize, nNameSize;
     GetEllipsoidSizeInfo(m_lMagic, nStructSize, nNameSize);
     if (strlen(kpName) > nNameSize-1) return NULL;
@@ -250,7 +241,6 @@
     }
     CS_fclose(pFile);
     return pDef;
-    */
 }
 
 //-----------------------------------------------------------------------------

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysGeodeticTransformDef.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysGeodeticTransformDef.cpp	2010-10-05 15:46:37 UTC (rev 5246)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysGeodeticTransformDef.cpp	2010-10-05 17:57:37 UTC (rev 5247)
@@ -179,7 +179,7 @@
 {
     VERIFY_INITIALIZED(L"CCoordinateSystemGeodeticTransformDef.CreateTransformation");
 
-    if (MgCoordinateSystemGeodeticTransformDefType::None == this->GetTransformDefType() || !this->IsValid())
+    if (!this->IsValid())
         throw new MgInvalidOperationException(L"CCoordinateSystemGeodeticTransformDef.CreateTransformation", __LINE__,__WFILE__, NULL, L"", NULL);
 
     //we don't take ownership of the transformation being returned but
@@ -316,6 +316,9 @@
         return false;
 
     Ptr<MgCoordinateSystemGeodeticTransformDefParams> params = this->GetParameters();
+    if (NULL == params)
+        return true; //this is a NULL transformation; this is valid
+
     if (!params->IsValid())
         return false;
 

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysGeodeticTransformation.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysGeodeticTransformation.cpp	2010-10-05 15:46:37 UTC (rev 5246)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysGeodeticTransformation.cpp	2010-10-05 17:57:37 UTC (rev 5247)
@@ -21,6 +21,7 @@
 #include "CoordSysUtil.h"                   //for Convert_Wide_To_Ascii, CsDictionaryOpenMode
 #include "MentorUtil.h"                     //for BuildDtDefFromInterface + various utilities
 
+#include "CoordSysGeodeticTransformDef.h"   //for CCoordinateSystemGeodeticTransformDef
 #include "CoordSysDatum.h"                  //for CCoordinateSystemDatum
 #include "CoordSysGeodeticTransformation.h" //for CCoordinateSystemGeodeticTransformation
 
@@ -40,7 +41,9 @@
 }
 
 //-----------------------------------------------------------------------------
-CCoordinateSystemGeodeticTransformation::CCoordinateSystemGeodeticTransformation(MgCoordinateSystemCatalog* pCatalog, MgCoordinateSystemGeodeticTransformDef* transformationDef, bool createInversed)
+CCoordinateSystemGeodeticTransformation::CCoordinateSystemGeodeticTransformation(MgCoordinateSystemCatalog* pCatalog,
+                                                                                 MgCoordinateSystemGeodeticTransformDef* transformationDef,
+                                                                                 bool createInversed)
 : m_pDtcprm(NULL), m_pDtSource(NULL), m_pDtTarget(NULL)
 {
     if (NULL == pCatalog || NULL == transformationDef)
@@ -360,18 +363,24 @@
 //
 void CCoordinateSystemGeodeticTransformation::SetupFromTransformationDef(MgCoordinateSystemGeodeticTransformDef* transformationDef, bool createInversed)
 {
-    char* transformName = Convert_Wide_To_Ascii(transformationDef->GetTransformName().c_str());
+    cs_Dtcprm_* datumTransform = NULL;
 
     MG_TRY()
 
-
     //protect the call to the lib files; the calls to the [datumDictionary] below
     //we also enter the critical section but on the same thread - i.e. no problem;
     //putting the check here saves us from [enter, leave, enter leave]
     SmartCriticalClass criticalSection(true);
 
+    CCoordinateSystemGeodeticTransformDef* transformDefImpl = dynamic_cast<CCoordinateSystemGeodeticTransformDef*>(transformationDef);
+    if (NULL == transformDefImpl)
+        throw new MgInvalidArgumentException(L"CCoordinateSystemGeodeticTransformation.SetupFromTransformationDef", __LINE__, __WFILE__, NULL, L"", NULL);
+
+    cs_GeodeticTransform_ csMapTransformDef;
+    transformDefImpl->CopyTo(csMapTransformDef);
+
     //ask CS_Map for the transformation
-    cs_Dtcprm_* datumTransform = CSdtcsu1(transformName, createInversed ? cs_DTCDIR_INV : cs_DTCDIR_FWD, cs_DTCFLG_BLK_W);
+    datumTransform = CSdtcsu2(&csMapTransformDef, createInversed ? cs_DTCDIR_INV : cs_DTCDIR_FWD, cs_DTCFLG_BLK_W);
 
     if (NULL == datumTransform)
         throw new MgInvalidArgumentException(L"CCoordinateSystemGeodeticTransformation.SetupFromTransformationDef", __LINE__, __WFILE__, NULL, L"", NULL);
@@ -381,12 +390,15 @@
     Ptr<MgCoordinateSystemDatum> trgDatum = datumDictionary->GetDatum(transformationDef->GetTargetDatum());
 
     this->m_pDtcprm = datumTransform;
+    datumTransform = NULL; //make sure, it's not being released below
+
     this->m_pDtSource = srcDatum.Detach();  //m_pDtSource is no auto pointer
     this->m_pDtTarget = trgDatum.Detach();  //m_pDtTarget is no auto pointer
 
     MG_CATCH(L"CCoordinateSystemGeodeticTransformation.SetupFromTransformationDef")
 
-    delete[] transformName;
+    if (NULL != datumTransform) //has been set to NULL after assignment
+        CS_free(datumTransform);
 
     MG_THROW()
 }

Modified: trunk/MgDev/Common/CoordinateSystem/MentorUtil.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/MentorUtil.cpp	2010-10-05 15:46:37 UTC (rev 5246)
+++ trunk/MgDev/Common/CoordinateSystem/MentorUtil.cpp	2010-10-05 17:57:37 UTC (rev 5247)
@@ -1357,41 +1357,43 @@
 {
     assert(NULL != pDtcprm);
 
-    INT32 nResult = 0;
+    //Skip datum transformation if we have a null transformation
+    //That is, if [pDtcprm->xfrmCount] is 0 or the transformation at index 0 is [cs_DTCMTH_NULLX];
+    //in either case, the entry at index 0 must never be NULL, if [xfrmCount] is not 0
+    assert(0 == pDtcprm->xfrmCount || NULL != pDtcprm->xforms[0]);
+    
+    bool isNullTransform = (0 == pDtcprm->xfrmCount || //is there a transformation entry at all?
+          (1 == pDtcprm->xfrmCount && NULL != pDtcprm->xforms[0] && cs_DTCMTH_NULLX == pDtcprm->xforms[0]->methodCode)); //if so, check, whether we've [cs_DTCMTH_NULLX] at index 0
 
-    // Skip datum transformation if we have a null transformation
-    // We have a null transform if the first transform type is dtcTypNone
+    if (isNullTransform)
+        return 0;
 
-    // FIXME
-    if (NULL != pDtcprm->xforms[0])
-    //if (dtcTypNone != pDtcprm->xforms[0].xfrmType) <-- doesn't compile
+    double dZ=0.;
+    if (pdZ)
     {
-        double dZ=0.;
-        if (pdZ)
-        {
-            dZ=*pdZ;
-        }
+        dZ=*pdZ;
+    }
 
-        CriticalClass.Enter();
-        double dLonLat[3] = { dLongitude, dLatitude, dZ };
-        INT32 nResult;
-        if (!pdZ)
-        {
-            nResult = CS_dtcvt(pDtcprm, dLonLat, dLonLat);
-        }
-        else
-        {
-            nResult = CS_dtcvt3D(pDtcprm, dLonLat, dLonLat);
-        }
-        CriticalClass.Leave();
+    CriticalClass.Enter();
+    double dLonLat[3] = { dLongitude, dLatitude, dZ };
+    INT32 nResult;
+    if (!pdZ)
+    {
+        nResult = CS_dtcvt(pDtcprm, dLonLat, dLonLat);
+    }
+    else
+    {
+        nResult = CS_dtcvt3D(pDtcprm, dLonLat, dLonLat);
+    }
+    CriticalClass.Leave();
 
-        dLongitude = dLonLat[0];
-        dLatitude = dLonLat[1];
-        if (pdZ)
-        {
-            *pdZ=dLonLat[2];
-        }
+    dLongitude = dLonLat[0];
+    dLatitude = dLonLat[1];
+    if (pdZ)
+    {
+        *pdZ=dLonLat[2];
     }
+    
     return nResult;
 }
 



More information about the mapguide-commits mailing list