[Liblas-commits] hg: resync geotiff srs code for geocentric support

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Mar 10 23:14:10 EST 2011


details:   http://hg.liblas.orghg/rev/75811ed2ed8e
changeset: 2900:75811ed2ed8e
user:      warmerdam at pobox.com
date:      Thu Mar 10 22:59:22 2011 -0500
description:
resync geotiff srs code for geocentric support

diffstat:

 src/gt_citation.cpp |  744 ++++++++++++++++++++++++++++++++++-----------------
 src/gt_citation.h   |   36 ++-
 src/gt_wkt_srs.cpp  |  352 ++++++++++++++++--------
 3 files changed, 756 insertions(+), 376 deletions(-)

diffs (truncated from 1485 to 300 lines):

diff -r 294e04679171 -r 75811ed2ed8e src/gt_citation.cpp
--- a/src/gt_citation.cpp	Tue Mar 08 13:23:04 2011 -0600
+++ b/src/gt_citation.cpp	Thu Mar 10 22:59:22 2011 -0500
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id$
+ * $Id: gt_citation.cpp 21848 2011-02-25 16:41:38Z warmerdam $
  *
  * Project:  GeoTIFF Driver
  * Purpose:  Implements special parsing of Imagine citation strings, and
@@ -31,156 +31,190 @@
 #include "cpl_port.h"
 #include "cpl_string.h"
 
-#include "geo_normalize.h"
 #include "geovalues.h"
-#include "ogr_spatialref.h"
+#include "gt_citation.h"
 
-// Ignore warning about redifinition.  We need to use 
-// the new windows functions for this.  We'll only 
-// warn on MSVC with /W4
-#if defined(WIN32) 
-#pragma warning( 4: 4005)
-#  define EQUALN(a,b,n)           (_strnicmp(a,b,n)==0)
-#  define EQUAL(a,b)              (_stricmp(a,b)==0)
-#pragma warning( default: 4005)
-#endif
-    
-#define nCitationNameTypes 9
-typedef enum 
-{
-  CitCsName = 0,
-  CitPcsName = 1,
-  CitProjectionName = 2,
-  CitLUnitsName = 3,
-  CitGcsName = 4,
-  CitDatumName = 5,
-  CitEllipsoidName = 6,
-  CitPrimemName = 7,
-  CitAUnitsName = 8
-} CitationNameType;
+CPL_CVSID("$Id: gt_citation.cpp 21848 2011-02-25 16:41:38Z warmerdam $");
 
-char* ImagineCitationTranslation(const char* psCitation, geokey_t keyID);
-char** CitationStringParse(const char* psCitation);
-void SetLinearUnitCitation(GTIF* psGTIF, char* pszLinearUOMName);
-void SetGeogCSCitation(GTIF * psGTIF, OGRSpatialReference *poSRS, char* angUnitName, int nDatum, short nSpheroid);
-OGRBoolean SetCitationToSRS(GTIF* hGTIF, char* szCTString, int nCTStringLen,
-                            geokey_t geoKey,  OGRSpatialReference* poSRS, OGRBoolean* linearUnitIsSet);
-void GetGeogCSFromCitation(char* szGCSName, int nGCSName,
-                           geokey_t geoKey, 
-                          char	**ppszGeogName,
-                          char	**ppszDatumName,
-                          char	**ppszPMName,
-                          char	**ppszSpheroidName,
-                          char	**ppszAngularUnits);
+static const char *apszUnitMap[] = {
+    "meters", "1.0",
+    "meter", "1.0",
+    "m", "1.0",
+    "centimeters", "0.01",
+    "centimeter", "0.01",
+    "cm", "0.01", 
+    "millimeters", "0.001",
+    "millimeter", "0.001",
+    "mm", "0.001",
+    "kilometers", "1000.0",
+    "kilometer", "1000.0",
+    "km", "1000.0",
+    "us_survey_feet", "0.3048006096012192",
+    "us_survey_foot", "0.3048006096012192",
+    "feet", "0.3048006096012192", 
+    "foot", "0.3048006096012192",
+    "ft", "0.3048006096012192",
+    "international_feet", "0.3048",
+    "international_foot", "0.3048",
+    "inches", "0.0254000508001",
+    "inch", "0.0254000508001",
+    "in", "0.0254000508001",
+    "yards", "0.9144",
+    "yard", "0.9144",
+    "yd", "0.9144",
+    "miles", "1304.544",
+    "mile", "1304.544",
+    "mi", "1304.544",
+    "modified_american_feet", "0.3048122530",
+    "modified_american_foot", "0.3048122530",
+    "clarke_feet", "0.3047972651",
+    "clarke_foot", "0.3047972651",
+    "indian_feet", "0.3047995142",
+    "indian_foot", "0.3047995142",
+    "Yard_Indian", "0.9143985307444408", 
+    "Foot_Clarke", "0.304797265",
+    "Foot_Gold_Coast", "0.3047997101815088",
+    "Link_Clarke", "0.2011661949", 
+    "Yard_Sears", "0.9143984146160287", 
+    "50_Kilometers", "50000.0", 
+    "150_Kilometers", "150000.0", 
+    NULL, NULL
+};
 
 /************************************************************************/
 /*                     ImagineCitationTranslation()                     */
 /*                                                                      */
 /*      Translate ERDAS Imagine GeoTif citation                         */
 /************************************************************************/
-char* ImagineCitationTranslation(const char* psCitation, geokey_t keyID)
+char* ImagineCitationTranslation(char* psCitation, geokey_t keyID)
 {
-    char* ret = NULL;
-    if(!psCitation)
-        return ret;
-    if(EQUALN(psCitation, "IMAGINE GeoTIFF Support", strlen("IMAGINE GeoTIFF Support")))
+  static const char *keyNames[] = {
+    "NAD = ", "Datum = ", "Ellipsoid = ", "Units = ", NULL
+  };
+
+  char* ret = NULL;
+  int i;
+  if(!psCitation)
+    return ret;
+  if(EQUALN(psCitation, "IMAGINE GeoTIFF Support", strlen("IMAGINE GeoTIFF Support")))
+  {
+    // this is a handle IMAGING style citation
+    char name[256];
+    name[0] = '\0';
+    char* p = NULL;
+    char* p1 = NULL;
+
+    p = strchr(psCitation, '$');
+    if( p && strchr(p, '\n') )
+      p = strchr(p, '\n') + 1;
+    if(p)
     {
-        CPLString osName;
+      p1 = p + strlen(p);
+      char *p2 = strchr(p, '\n');
+      if(p2)
+        p1 = MIN(p1, p2);
+      p2 = strchr(p, '\0');
+      if(p2)
+        p1 = MIN(p1, p2);
+      for(i=0; keyNames[i]!=NULL; i++)
+      {
+        p2 = strstr(p, keyNames[i]);
+        if(p2)
+          p1 = MIN(p1, p2);
+      }
+    }
 
-        // this is a handle IMAGING style citation
-        const char* p = NULL;
-        p = strchr(psCitation, '$');
-        if(p)
-            p = strchr(p, '\n');
-        if(p)
-            p++;
-        const char* p1 = NULL;
-        if(p)
-            p1 = strchr(p, '\n');
-        if(p && p1)
+    // PCS name, GCS name and PRJ name
+    if(p && p1)
+    {
+      switch (keyID)
+      {
+        case PCSCitationGeoKey:
+          if(strstr(psCitation, "Projection = "))
+            strcpy(name, "PRJ Name = ");
+          else
+            strcpy(name, "PCS Name = ");
+        break;
+        case GTCitationGeoKey:
+          strcpy(name, "PCS Name = ");
+        break;
+        case GeogCitationGeoKey:
+          if(!strstr(p, "Unable to"))
+            strcpy(name, "GCS Name = ");
+        break;
+        default:
+        break;
+      }
+      if(strlen(name)>0)
+      {
+        char* p2;
+        if((p2 = strstr(psCitation, "Projection Name = ")) != 0)
+          p = p2 + strlen("Projection Name = ");
+        if((p2 = strstr(psCitation, "Projection = ")) != 0)
+          p = p2 + strlen("Projection = ");
+        if(p1[0] == '\0' || p1[0] == '\n' || p1[0] == ' ')
+          p1 --;
+        p2 = p1 - 1;
+        while( p2>0 && (p2[0] == ' ' || p2[0] == '\0' || p2[0] == '\n') )
+          p2--;
+        if(p2 != p1 - 1)
+          p1 = p2;
+        if(p1 >= p)
         {
-            switch (keyID)
-            {
-              case PCSCitationGeoKey:
-                osName = "PCS Name = ";
-                break;
-              case GTCitationGeoKey:
-                osName = "CS Name = ";
-                break;
-              case GeogCitationGeoKey:
-                if(!strstr(p, "Unable to"))
-                    osName = "GCS Name = ";
-                break;
-              default:
-                break;
-            }
-            if(strlen(osName)>0)
-            {
-                osName.append(p, p1-p);
-                osName += "|";
-            }
+          strncat(name, p, p1-p+1);
+          strcat(name, "|");
+          name[strlen(name)] = '\0';
         }
-        p = strstr(psCitation, "Projection Name = ");
-        if(p)
+      }
+    }
+
+    // All other parameters
+    for(i=0; keyNames[i]!=NULL; i++)
+    {
+      p = strstr(psCitation, keyNames[i]);
+      if(p)
+      {
+        p += strlen(keyNames[i]);
+        p1 = p + strlen(p);
+        char *p2 = strchr(p, '\n');
+        if(p2)
+          p1 = MIN(p1, p2);
+        p2 = strchr(p, '\0');
+        if(p2)
+          p1 = MIN(p1, p2);
+        for(int j=0; keyNames[j]!=NULL; j++)
         {
-            p += strlen("Projection Name = ");
-            p1 = strchr(p, '\n');
-            if(!p1)
-                p1 = strchr(p, '\0');
+          p2 = strstr(p, keyNames[j]);
+          if(p2)
+            p1 = MIN(p1, p2);
         }
-        if(p && p1)
+      }
+      if(p && p1 && p1>p)
+      {
+        if(EQUAL(keyNames[i], "Units = "))
+          strcat(name, "LUnits = ");
+        else
+          strcat(name, keyNames[i]);
+        if(p1[0] == '\0' || p1[0] == '\n' || p1[0] == ' ')
+          p1 --;
+        char* p2 = p1 - 1;
+        while( p2>0 && (p2[0] == ' ' || p2[0] == '\0' || p2[0] == '\n') )
+          p2--;
+        if(p2 != p1 - 1)
+          p1 = p2;
+        if(p1 >= p)
         {
-            osName.append(p, p1-p);
-            osName += "|";
+          strncat(name, p, p1-p+1);
+          strcat(name, "|");
+          name[strlen(name)] = '\0';
         }
-        p = strstr(psCitation, "Datum = ");
-        if(p)
-        {
-            p += strlen("Datum = ");
-            p1 = strchr(p, '\n');
-            if(!p1)
-                p1 = strchr(p, '\0');
-        }
-        if(p && p1)
-        {
-            osName += "Datum = ";
-            osName.append(p, p1-p);
-            osName += "|";
-        }
-        p = strstr(psCitation, "Ellipsoid = ");
-        if(p)
-        {
-            p += strlen("Ellipsoid = ");
-            p1 = strchr(p, '\n');
-            if(!p1)
-                p1 = strchr(p, '\0');
-        }
-        if(p && p1)
-        {
-            osName += "Ellipsoid = ";


More information about the Liblas-commits mailing list