[mapserver-commits] r7698 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Wed Jun 18 21:19:20 EDT 2008


Author: tomkralidis
Date: 2008-06-18 21:19:20 -0400 (Wed, 18 Jun 2008)
New Revision: 7698

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapgml.c
   trunk/mapserver/mapogcsos.c
   trunk/mapserver/mapsde.c
   trunk/mapserver/mapserver.h
   trunk/mapserver/mapstring.c
Log:
add srsName support for GetObservation (#2414)


Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2008-06-18 22:45:02 UTC (rev 7697)
+++ trunk/mapserver/HISTORY.TXT	2008-06-19 01:19:20 UTC (rev 7698)
@@ -13,6 +13,8 @@
 Current Version (SVN trunk):
 ----------------------------
 
+- mapogcsos.c: support srsName in GetObservation (#2414)
+
 - Filter Encoding: Modify DWithin definition (#2564)
 
 - Added webObj legendformat and browseformat mapping in PHP MapScript (#2309)

Modified: trunk/mapserver/mapgml.c
===================================================================
--- trunk/mapserver/mapgml.c	2008-06-18 22:45:02 UTC (rev 7697)
+++ trunk/mapserver/mapgml.c	2008-06-19 01:19:20 UTC (rev 7698)
@@ -1582,17 +1582,17 @@
     free(pszTmp);
   }
 
-  pszTmp = msDoubleToString(minx);
+  pszTmp = msDoubleToString(minx, MS_TRUE);
   pszTmp = msStringConcatenate(pszTmp, " ");
-  pszTmp2 = msDoubleToString(miny);
+  pszTmp2 = msDoubleToString(miny, MS_TRUE);
   pszTmp = msStringConcatenate(pszTmp, pszTmp2);
   psSubSubNode = xmlNewChild(psSubNode, NULL, BAD_CAST "lowerCorner", BAD_CAST pszTmp);
   free(pszTmp);
   free(pszTmp2);
 
-  pszTmp = msDoubleToString(maxx);
+  pszTmp = msDoubleToString(maxx, MS_TRUE);
   pszTmp = msStringConcatenate(pszTmp, " ");
-  pszTmp2 = msDoubleToString(maxy); 
+  pszTmp2 = msDoubleToString(maxy,MS_TRUE); 
   pszTmp = msStringConcatenate(pszTmp, pszTmp2);
   psSubSubNode = xmlNewChild(psSubNode, NULL, BAD_CAST "upperCorner", BAD_CAST pszTmp);
   free(pszTmp);
@@ -1640,9 +1640,9 @@
     free(pszTmp);
   }
 
-  pszTmp = msDoubleToString(x);
+  pszTmp = msDoubleToString(x, MS_TRUE);
   pszTmp = msStringConcatenate(pszTmp, " ");
-  pszTmp = msStringConcatenate(pszTmp, msDoubleToString(y));
+  pszTmp = msStringConcatenate(pszTmp, msDoubleToString(y, MS_TRUE));
   psSubNode = xmlNewChild(psNode, NULL, BAD_CAST "pos", BAD_CAST pszTmp);
 
   free(pszTmp);

Modified: trunk/mapserver/mapogcsos.c
===================================================================
--- trunk/mapserver/mapogcsos.c	2008-06-18 22:45:02 UTC (rev 7697)
+++ trunk/mapserver/mapogcsos.c	2008-06-19 01:19:20 UTC (rev 7698)
@@ -347,7 +347,7 @@
 /*      from gmlWriteGeometry_GML2. Should be merged at one point if    */
 /*      possible.                                                       */
 /************************************************************************/
-void  msSOSAddGeometryNode(xmlNsPtr psNsGml, xmlNodePtr psParent, layerObj *lp, shapeObj *psShape, 
+void  msSOSAddGeometryNode(xmlNsPtr psNsGml, xmlNodePtr psParent, mapObj *map, layerObj *lp, shapeObj *psShape, 
                            const char *pszEpsg)
 {
     char *pszTmp = NULL;
@@ -357,6 +357,11 @@
 
     if (psParent && psShape)
     {
+      if (msProjectionsDiffer(&map->projection, &lp->projection) == MS_TRUE) 
+      {
+        msProjectShape(&lp->projection, &map->projection, psShape);
+        pszEpsg = msOWSGetEPSGProj(&(map->projection), &(lp->metadata), "SO", MS_TRUE);
+      }
         switch(psShape->type) 
         {
             case(MS_SHAPE_POINT):
@@ -423,10 +428,10 @@
                   for(j=0; j<psShape->line[i].numpoints; j++)
                   {
                       pszTmp = msStringConcatenate(pszTmp, 
-                                           msDoubleToString(psShape->line[i].point[j].x));
+                                           msDoubleToString(psShape->line[i].point[j].x, MS_TRUE));
                       pszTmp = msStringConcatenate(pszTmp, ",");
                       pszTmp = msStringConcatenate(pszTmp, 
-                                           msDoubleToString(psShape->line[i].point[j].y));
+                                           msDoubleToString(psShape->line[i].point[j].y, MS_TRUE));
                       pszTmp = msStringConcatenate(pszTmp, " ");
                   }
                   psNode = xmlNewChild(psNode, NULL, BAD_CAST "coordinates", BAD_CAST pszTmp);
@@ -492,11 +497,11 @@
   
                       pszTmp = 
                         msStringConcatenate(pszTmp, 
-                                    msDoubleToString(psShape->line[i].point[j].x));
+                                    msDoubleToString(psShape->line[i].point[j].x, MS_TRUE));
                       pszTmp = msStringConcatenate(pszTmp, ",");
                       pszTmp = 
                         msStringConcatenate(pszTmp, 
-                                    msDoubleToString(psShape->line[i].point[j].y));
+                                    msDoubleToString(psShape->line[i].point[j].y, MS_TRUE));
                       pszTmp = msStringConcatenate(pszTmp, " ");
                   }
                   psNode = xmlNewChild(psNode, NULL, BAD_CAST "coordinates", BAD_CAST pszTmp);
@@ -796,14 +801,17 @@
         
         /*bbox*/
 #ifdef USE_PROJ
-        pszEpsg = msOWSGetEPSGProj(&(map->projection), &(map->web.metadata), "SO", MS_TRUE);
+        pszEpsg = msOWSGetEPSGProj(&(map->projection), &(lp->metadata), "SO", MS_TRUE);
         if (!pszEpsg)
           pszEpsg = msOWSGetEPSGProj(&(lp->projection), &(lp->metadata), "SO", MS_TRUE);
+
+        if (msProjectionsDiffer(&map->projection, &lp->projection) == MS_TRUE)
+              msProjectRect(&lp->projection, &map->projection, &sShape.bounds);
 #endif        
         psNode = xmlAddChild(psLayerNode, msGML3BoundedBy(psNsGml, sShape.bounds.minx, sShape.bounds.miny, sShape.bounds.maxx, sShape.bounds.maxy, pszEpsg));
 
         /*geometry*/
-        msSOSAddGeometryNode(psNsGml, psLayerNode, lp, &sShape, pszEpsg);
+        msSOSAddGeometryNode(psNsGml, psLayerNode, map, lp, &sShape, pszEpsg);
 
         /*attributes */
         /* TODO only output attributes where there is a sos_%s_alias (to be discussed)*/
@@ -2044,6 +2052,64 @@
         map->extent.maxy = sBbox.maxy;
   }
 
+  if (sosparams->pszSrsName) { /* validate against MAP.WEB.METADATA.sos_srs */
+    int iUnits = -1;
+    char **tokens = NULL;
+    const char *pszSRSList = NULL;
+    int n = 0;
+    int bFound = 0;
+    int k;
+    char srsbuffer[100];
+    projectionObj po;
+
+    pszSRSList = msOWSLookupMetadata(&(map->web.metadata), "SO", "srs");
+
+    if (pszSRSList) {
+      tokens = msStringSplit(pszSRSList, ' ', &n);
+
+      if (tokens && n > 0) {
+        for (k=0; k<n; k++) {
+          if (strcasecmp(sosparams->pszSrsName, tokens[k]) == 0) { /* match */
+            bFound = 1;
+
+            /* project MAP.EXTENT to this SRS */
+            msInitProjection(&po);
+
+            sprintf(srsbuffer, "+init=epsg:%.20s", sosparams->pszSrsName+5);
+
+            if (msLoadProjectionString(&po, srsbuffer) != 0) {
+              msSetError(MS_SOSERR, "Could not set output projection to \"%s\"", "msSOSGetObservation()", sosparams->pszSrsName);
+              return msSOSException(map, "mapserv", "NoApplicableCode");
+            }
+
+            if (msProjectionsDiffer(&map->projection, &po) == MS_TRUE) {
+              msProjectRect(&map->projection, &po, &map->extent);
+              sBbox = map->extent;
+            }
+
+            /* set map->projection to this SRS */
+            if (msLoadProjectionString(&(map->projection), srsbuffer) != 0) {
+              msSetError(MS_SOSERR, "Could not set output projection to \"%s\"", "msSOSGetObservation()", sosparams->pszSrsName);
+              return msSOSException(map, "mapserv", "NoApplicableCode");
+            }
+                 
+            iUnits = GetMapserverUnitUsingProj(&(map->projection));
+            if (iUnits != -1)
+              map->units = iUnits;
+                
+            msFreeProjection(&po);
+            break;
+          }
+        }
+        msFreeCharArray(tokens, n);
+      }
+      if (bFound == 0) {
+        msSetError(MS_SOSERR, "srsName value \"%s\" unsupported / invalid", "msSOSGetObservation()", sosparams->pszSrsName);
+        return msSOSException(map, "srsName", "InvalidParameterValue");
+      }
+    }
+  }
+
   /* apply filter */
   if (sosparams->pszResult) {
     psFilterNode = FLTParseFilterEncoding(sosparams->pszResult);
@@ -2155,14 +2221,34 @@
     {
        char **tokens;
        int n;
-       pszTmp2 = msOWSGetEPSGProj(&(lp->projection), &(lp->metadata), "SO", MS_TRUE);
+       rectObj envelope;
+
+       pszTmp2 = msOWSGetEPSGProj(&(map->projection), &(lp->metadata), "SO", MS_TRUE);
+
        tokens = msStringSplit(pszTmp, ',', &n);
        if (tokens==NULL || n != 4) {
           msSetError(MS_SOSERR, "Wrong number of arguments for offering_extent.",
           "msSOSGetCapabilities()");
           return msSOSException(map, "offering_extent", "InvalidParameterValue");
        }
-       psNode = xmlAddChild(psRootNode, msGML3BoundedBy(psNsGml, atof(tokens[0]), atof(tokens[1]), atof(tokens[2]), atof(tokens[3]), pszTmp2));
+
+       envelope.minx = atof(tokens[0]);
+       envelope.miny = atof(tokens[1]);
+       envelope.maxx = atof(tokens[2]);
+       envelope.maxy = atof(tokens[3]);
+
+       if (map && msProjectionsDiffer(&map->projection, &lp->projection) == MS_TRUE) {
+         if (msProjectRect(&lp->projection, &map->projection, &envelope) == MS_FAILURE){ 
+           msSetError(MS_SOSERR, "Coordinates transformation failed.  Raised in msProjectRect() of file %s line %d", "msSOSGetCapabilities()", __FILE__, __LINE__);
+           return msSOSException(map, "offering_extent", "InvalidParameterValue");
+         }
+       }
+
+       //msSetError(MS_SOSERR, "%f %f %f %f", "msSOSGetCapabilities()", envelope.minx, envelope.miny, envelope.maxx, envelope.maxy);
+       //return msSOSException(map, "offering_extent", "InvalidParameterValue");
+
+       //psNode = xmlAddChild(psRootNode, msGML3BoundedBy(psNsGml, atof(tokens[0]), atof(tokens[1]), atof(tokens[2]), atof(tokens[3]), pszTmp2));
+       psNode = xmlAddChild(psRootNode, msGML3BoundedBy(psNsGml, envelope.minx, envelope.miny, envelope.maxx, envelope.maxy, pszTmp2));
        msFreeCharArray(tokens, n);
     }
 
@@ -2803,7 +2889,7 @@
     xmlXPathFreeObject(psXPathTmp);
 
     /* check for eventTime (chunk of XML) */
-    psXPathTmp = msLibXml2GetXPath(doc, context, (xmlChar *)"/sos:GetObservation/sos:eventTime/ogc:TM_Equals/gml:TimeInstant|/sos:GetObservation/sos:eventTime/ogc:TM_Equals/gml:TimePeriod");
+    psXPathTmp = msLibXml2GetXPath(doc, context, (xmlChar *)"/sos:GetObservation/sos:eventTime/*/gml:TimeInstant|/sos:GetObservation/sos:eventTime/*/gml:TimePeriod");
 
     if (psXPathTmp) {
       sosparams->pszEventTime = (char *)msLibXml2GetXPathTree(doc, psXPathTmp);

Modified: trunk/mapserver/mapsde.c
===================================================================
--- trunk/mapserver/mapsde.c	2008-06-18 22:45:02 UTC (rev 7697)
+++ trunk/mapserver/mapsde.c	2008-06-19 01:19:20 UTC (rev 7698)
@@ -688,7 +688,7 @@
                                             (short)(i+1), 
                                             &floatval); 
             if(status == SE_SUCCESS)
-                shape->values[i] = msDoubleToString(floatval);
+                shape->values[i] = msDoubleToString(floatval, MS_FALSE);
             else if(status == SE_NULL_VALUE)
                 shape->values[i] = strdup(MS_SDE_NULLSTRING);
             else {     
@@ -703,7 +703,7 @@
                                             (short) (i+1), 
                                             &doubleval);
             if(status == SE_SUCCESS)
-                shape->values[i] = msDoubleToString(doubleval);
+                shape->values[i] = msDoubleToString(doubleval, MS_FALSE);
             else if(status == SE_NULL_VALUE)
                 shape->values[i] = strdup(MS_SDE_NULLSTRING);
             else {     

Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h	2008-06-18 22:45:02 UTC (rev 7697)
+++ trunk/mapserver/mapserver.h	2008-06-19 01:19:20 UTC (rev 7698)
@@ -1602,7 +1602,7 @@
 MS_DLL_EXPORT char **msStringSplit(const char *string, char cd, int *num_tokens);
 MS_DLL_EXPORT int msCountChars(char *str, char ch);
 MS_DLL_EXPORT char *msLongToString(long value);
-MS_DLL_EXPORT char *msDoubleToString(double value);
+MS_DLL_EXPORT char *msDoubleToString(double value, int force_f);
 MS_DLL_EXPORT char *msIntToString(int value);
 MS_DLL_EXPORT void msStringToUpper(char *string);
 MS_DLL_EXPORT void msStringToLower(char *string);

Modified: trunk/mapserver/mapstring.c
===================================================================
--- trunk/mapserver/mapstring.c	2008-06-18 22:45:02 UTC (rev 7697)
+++ trunk/mapserver/mapstring.c	2008-06-19 01:19:20 UTC (rev 7698)
@@ -244,10 +244,13 @@
   return(strdup(buffer));
 }
 
-char *msDoubleToString(double value) {
+char *msDoubleToString(double value, int force_f) {
   char buffer[256]; /* plenty of space */
 
-  sprintf(buffer, "%g", value);
+  if (force_f == MS_TRUE)
+    sprintf(buffer, "%f", value);
+  else
+    sprintf(buffer, "%g", value);
   return(strdup(buffer));
 }
 



More information about the mapserver-commits mailing list