[mapserver-commits] r11969 - in trunk/mapserver: . mapscript/php mapscript/swiginc

svn at osgeo.org svn at osgeo.org
Thu Jul 21 10:17:07 EDT 2011


Author: assefa
Date: 2011-07-21 07:17:06 -0700 (Thu, 21 Jul 2011)
New Revision: 11969

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapogcsld.c
   trunk/mapserver/mapscript/php/mapscript_i.c
   trunk/mapserver/mapscript/swiginc/layer.i
   trunk/mapserver/mapscript/swiginc/map.i
   trunk/mapserver/mapwms.c
Log:
WMS: LAYERS parameter is optional when sld is given (#1166)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2011-07-21 13:58:51 UTC (rev 11968)
+++ trunk/mapserver/HISTORY.TXT	2011-07-21 14:17:06 UTC (rev 11969)
@@ -14,6 +14,9 @@
 
 Current Version (SVN trunk, 6.1-dev, future 6.2): 
 -------------------------------------------------
+
+- WMS: LAYERS parameter is optional when sld is given (#1166)
+
 - Add runtime substitution for "filename" output format option (#3571) and
   allow setting defaults in either metadata or validation (preferred) blocks
   for both layer and output format.

Modified: trunk/mapserver/mapogcsld.c
===================================================================
--- trunk/mapserver/mapogcsld.c	2011-07-21 13:58:51 UTC (rev 11968)
+++ trunk/mapserver/mapogcsld.c	2011-07-21 14:17:06 UTC (rev 11969)
@@ -59,7 +59,7 @@
 /*      used to do the match.                                           */
 /************************************************************************/
 int msSLDApplySLDURL(mapObj *map, char *szURL, int iLayer,
-                     char *pszStyleLayerName)
+                     char *pszStyleLayerName,  char **ppszLayerNames)
 {
 #ifdef USE_OGR
 
@@ -99,7 +99,7 @@
             msSetError(MS_WMSERR, "Could not open SLD %s and save it in temporary file %s. Please make sure that the sld url is valid and that the temporary path is set. The temporary path can be defined for example by setting TMPPATH in the map file. Please check the MapServer documentation on temporary path settings.", "msSLDApplySLDURL", szURL, pszSLDTmpFile);
         }
         if (pszSLDbuf)
-          nStatus = msSLDApplySLD(map, pszSLDbuf, iLayer, pszStyleLayerName);
+          nStatus = msSLDApplySLD(map, pszSLDbuf, iLayer, pszStyleLayerName, ppszLayerNames);
     }
 
     return nStatus;
@@ -130,7 +130,7 @@
 /*      the SLD layers onto the map layers.                             */
 /************************************************************************/
 int msSLDApplySLD(mapObj *map, char *psSLDXML, int iLayer,
-                  char *pszStyleLayerName)
+                  char *pszStyleLayerName, char **ppszLayerNames)
 {
 #if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR)
 
@@ -505,6 +505,26 @@
               break;
         }
 	
+/* -------------------------------------------------------------------- */
+/*      if needed return a comma separated list of the layers found     */
+/*      in the sld.                                                     */
+/* -------------------------------------------------------------------- */
+        if (ppszLayerNames)
+        {
+            char *pszTmp = NULL;
+            for (i=0; i<nLayers; i++)
+            {
+                if (pasLayers[i].name)
+                {
+                    if (pszTmp !=NULL)
+                      pszTmp = msStringConcatenate(pszTmp, ",");
+                    pszTmp = msStringConcatenate(pszTmp, pasLayers[i].name);
+
+                }
+            }
+            *ppszLayerNames = pszTmp;
+            
+        }
 	for (i=0; i<nLayers; i++)
 	  freeLayer(&pasLayers[i]);
 	msFree(pasLayers);
@@ -2219,7 +2239,7 @@
 
     char *pszFormat = NULL;
     CPLXMLNode *psURL=NULL, *psFormat=NULL, *psTmp=NULL;
-    char *pszURL=NULL, *pszTmpSymbolName=NULL;
+    char *pszURL=NULL;
     int status;
 
 

Modified: trunk/mapserver/mapscript/php/mapscript_i.c
===================================================================
--- trunk/mapserver/mapscript/php/mapscript_i.c	2011-07-21 13:58:51 UTC (rev 11968)
+++ trunk/mapserver/mapscript/php/mapscript_i.c	2011-07-21 14:17:06 UTC (rev 11969)
@@ -352,11 +352,11 @@
 
 int mapObj_applySLD(mapObj *self, char *sld)
 {
-    return msSLDApplySLD(self, sld, -1, NULL);
+  return msSLDApplySLD(self, sld, -1, NULL, NULL);
 }
 int mapObj_applySLDURL(mapObj *self, char *sld)
 {
-    return msSLDApplySLDURL(self, sld, -1, NULL);
+  return msSLDApplySLDURL(self, sld, -1, NULL, NULL);
 }
 
 char *mapObj_generateSLD(mapObj *self)
@@ -677,11 +677,11 @@
 
 int layerObj_applySLD(layerObj *self, char *sld, char *stylelayer)
 {
-    return msSLDApplySLD(self->map, sld, self->index, stylelayer);
+  return msSLDApplySLD(self->map, sld, self->index, stylelayer, NULL);
 }
 int layerObj_applySLDURL(layerObj *self, char *sld, char *stylelayer)
 {
-    return msSLDApplySLDURL(self->map, sld, self->index, stylelayer);
+  return msSLDApplySLDURL(self->map, sld, self->index, stylelayer, NULL);
 }
 
 char *layerObj_generateSLD(layerObj *self)

Modified: trunk/mapserver/mapscript/swiginc/layer.i
===================================================================
--- trunk/mapserver/mapscript/swiginc/layer.i	2011-07-21 13:58:51 UTC (rev 11968)
+++ trunk/mapserver/mapscript/swiginc/layer.i	2011-07-21 14:17:06 UTC (rev 11969)
@@ -559,12 +559,12 @@
 
     int applySLD(char *sld, char *stylelayer) 
     {
-        return msSLDApplySLD(self->map, sld, self->index, stylelayer);
+      return msSLDApplySLD(self->map, sld, self->index, stylelayer, NULL);
     }
 
     int applySLDURL(char *sld, char *stylelayer) 
     {
-        return msSLDApplySLDURL(self->map, sld, self->index, stylelayer);
+      return msSLDApplySLDURL(self->map, sld, self->index, stylelayer, NULL);
     }
 
     %newobject generateSLD; 

Modified: trunk/mapserver/mapscript/swiginc/map.i
===================================================================
--- trunk/mapserver/mapscript/swiginc/map.i	2011-07-21 13:58:51 UTC (rev 11968)
+++ trunk/mapserver/mapscript/swiginc/map.i	2011-07-21 14:17:06 UTC (rev 11969)
@@ -436,11 +436,11 @@
   /* SLD */
   
     int applySLD(char *sld) {
-        return msSLDApplySLD(self, sld, -1, NULL);
+      return msSLDApplySLD(self, sld, -1, NULL, NULL);
     }
 
     int applySLDURL(char *sld) {
-        return msSLDApplySLDURL(self, sld, -1, NULL);
+      return msSLDApplySLDURL(self, sld, -1, NULL, NULL);
     }
     
     %newobject generateSLD;

Modified: trunk/mapserver/mapwms.c
===================================================================
--- trunk/mapserver/mapwms.c	2011-07-21 13:58:51 UTC (rev 11968)
+++ trunk/mapserver/mapwms.c	2011-07-21 14:17:06 UTC (rev 11969)
@@ -420,8 +420,41 @@
 
    msAdjustExtent(&(map->extent), map->width, map->height);
 
-   
+   /*
+     Check for SLDs first. If SLD is available LAYERS and STYLES parameters are non mandatory
+    */
+   for(i=0; map && i<numentries; i++)
+   {
+       /* check if SLD is passed.  If yes, check for OGR support */
+       if (strcasecmp(names[i], "SLD") == 0 || strcasecmp(names[i], "SLD_BODY") == 0)
+       {
+           sldenabled = msOWSLookupMetadata(&(map->web.metadata), "MO", "sld_enabled");
 
+           if (sldenabled == NULL)
+             sldenabled = "true";
+
+           if (ogrEnabled == 0)
+           {
+               msSetError(MS_WMSERR, "OGR support is not available.", "msWMSLoadGetMapParams()");
+               return msWMSException(map, nVersion, NULL, wms_exception_format);
+           }
+           else
+           {
+               if (strcasecmp(sldenabled, "true") == 0)
+               {
+                   if (strcasecmp(names[i], "SLD") == 0)
+                   {
+                       sld_url =  values[i];
+                   }
+                   if (strcasecmp(names[i], "SLD_BODY") == 0)
+                   {
+                       sld_body =  values[i];
+                   }
+               }
+           }
+       }
+   }
+
    for(i=0; map && i<numentries; i++)
    {
     /* getMap parameters */
@@ -432,35 +465,8 @@
     }
 
     
-    /* check if SLD is passed.  If yes, check for OGR support */
-    if (strcasecmp(names[i], "SLD") == 0 || strcasecmp(names[i], "SLD_BODY") == 0)
-    {
-       sldenabled = msOWSLookupMetadata(&(map->web.metadata), "MO", "sld_enabled");
+   
 
-       if (sldenabled == NULL)
-         sldenabled = "true";
-
-       if (ogrEnabled == 0)
-       {
-          msSetError(MS_WMSERR, "OGR support is not available.", "msWMSLoadGetMapParams()");
-          return msWMSException(map, nVersion, NULL, wms_exception_format);
-       }
-       else
-       {
-          if (strcasecmp(sldenabled, "true") == 0)
-          {
-            if (strcasecmp(names[i], "SLD") == 0)
-            {
-              sld_url =  values[i];
-            }
-            if (strcasecmp(names[i], "SLD_BODY") == 0)
-            {
-              sld_body =  values[i];
-            }
-          }
-       }
-    }
-
     if (strcasecmp(names[i], "LAYERS") == 0)
     {
       int  j, k, iLayer, *layerOrder;
@@ -469,10 +475,14 @@
       MS_CHECK_ALLOC(layerOrder, map->numlayers * sizeof(int), MS_FAILURE)
 
       layers = msStringSplit(values[i], ',', &numlayers);
-      if (layers==NULL || strlen(values[i]) <=0 ||   numlayers < 1) {
-        msSetError(MS_WMSERR, "At least one layer name required in LAYERS.",
-                   "msWMSLoadGetMapParams()");
-        return msWMSException(map, nVersion, NULL, wms_exception_format);
+      if (layers==NULL || strlen(values[i]) <=0 ||   numlayers < 1) 
+      {
+          if (sld_url == NULL &&   sld_body == NULL)
+          {
+              msSetError(MS_WMSERR, "At least one layer name required in LAYERS.",
+                         "msWMSLoadGetMapParams()");
+              return msWMSException(map, nVersion, NULL, wms_exception_format);
+          }
       }
 
       if (nVersion >= OWS_1_3_0) {
@@ -864,9 +874,17 @@
   */
   if (validlayers == 0 || invalidlayers > 0)
   {
-      msSetError(MS_WMSERR, "Invalid layer(s) given in the LAYERS parameter.",
-                 "msWMSLoadGetMapParams()");
-      return msWMSException(map, nVersion, "LayerNotDefined", wms_exception_format);
+      if (invalidlayers > 0)
+      {
+          msSetError(MS_WMSERR, "Invalid layer(s) given in the LAYERS parameter.",
+                     "msWMSLoadGetMapParams()");
+          return msWMSException(map, nVersion, "LayerNotDefined", wms_exception_format);
+      }
+      if (validlayers == 0 && sld_url == NULL &&   sld_body == NULL)
+      {
+          msSetError(MS_WMSERR, "Missing required parameter LAYERS", "msWMSLoadGetMapParams()");
+          return msWMSException(map, nVersion, "MissingParameterValue", wms_exception_format);
+      }
   }
 
   /* validate srs value: When the SRS parameter in a GetMap request contains a
@@ -1080,16 +1098,32 @@
   {
        int nLayersBefore, nLayerAfter;
        char request_tmp[32];
+       char *pszLayerNames = NULL;
        nLayersBefore = map->numlayers;
-  /*apply sld if defined. This is done here so that bbox and srs are already applied*/
+
+
+/* -------------------------------------------------------------------- */
+/*      if LAYERS parameter was not given, set all layers to off        */
+/* -------------------------------------------------------------------- */
+       if (validlayers == 0) /*no LAYERS parameter is give*/
+       {        
+           for(j=0; j<map->numlayers; j++)
+           {
+                if (GET_LAYER(map, j)->status != MS_DEFAULT)
+                  GET_LAYER(map, j)->status = MS_OFF;
+           }
+       }
+
+
+       /*apply sld if defined. This is done here so that bbox and srs are already applied*/
        if (sld_url)
        {
-           if ((status = msSLDApplySLDURL(map, sld_url, -1, NULL)) != MS_SUCCESS)
+           if ((status = msSLDApplySLDURL(map, sld_url, -1, NULL, &pszLayerNames)) != MS_SUCCESS)
              return msWMSException(map, nVersion, NULL, wms_exception_format);
        }
        else if (sld_body)
        {
-           if ((status =msSLDApplySLD(map, sld_body, -1, NULL)) != MS_SUCCESS)
+           if ((status =msSLDApplySLD(map, sld_body, -1, NULL, &pszLayerNames)) != MS_SUCCESS)
              return msWMSException(map, nVersion, NULL, wms_exception_format);
        }
 /* -------------------------------------------------------------------- */
@@ -1103,6 +1137,43 @@
            strlcpy(request_tmp, "GetMap", sizeof(request_tmp));
            msOWSRequestLayersEnabled(map, "M", request_tmp, ows_request); 
        }
+
+/* -------------------------------------------------------------------- */
+/*      We need to take into account where the LAYERS parameter was     */
+/*      not given (the LAYERS is option when an SLD is given). In       */
+/*      this particular case, we need to turn on the layers             */
+/*      identified the SLD (#1166).                                     */
+/*                                                                      */
+/* -------------------------------------------------------------------- */
+       if (validlayers == 0)
+       {
+           if (pszLayerNames)
+           {
+               char **tokens;
+               int ntokens=0;
+               tokens = msStringSplit(pszLayerNames, ',', &ntokens);
+               if (ntokens >0)
+               {
+                   for (i=0; i<ntokens; i++)
+                   {
+                        for (j=0; j<map->numlayers; j++)
+                        {
+                            if ( ((GET_LAYER(map, j)->name &&
+                                   strcasecmp(GET_LAYER(map, j)->name, tokens[i]) == 0) ||
+                                  (map->name && strcasecmp(map->name, tokens[i]) == 0) ||
+                                  (GET_LAYER(map, j)->group && strcasecmp(GET_LAYER(map, j)->group, tokens[i]) == 0)) &&
+                                 ((msIntegerInArray(GET_LAYER(map, j)->index, ows_request->enabled_layers, ows_request->numlayers))) )
+                            {
+                                if (GET_LAYER(map, j)->status != MS_DEFAULT)
+                                  GET_LAYER(map, j)->status = MS_ON;
+                            }    
+                        }
+                   }
+               }
+           }
+       }
+       msFree(pszLayerNames);
+       
   }
   /* Validate Styles :
   ** MapServer advertize styles through th group setting in a class object.
@@ -3650,10 +3721,10 @@
 /* -------------------------------------------------------------------- */
          else if (strcasecmp(names[i], "SLD") == 0 &&
                   values[i] && strlen(values[i]) > 0 && strcasecmp(sldenabled, "true") == 0)
-             msSLDApplySLDURL(map, values[i], -1, NULL);
+           msSLDApplySLDURL(map, values[i], -1, NULL, NULL);
          else if (strcasecmp(names[i], "SLD_BODY") == 0 &&
                   values[i] && strlen(values[i]) > 0 && strcasecmp(sldenabled, "true") == 0)
-             msSLDApplySLD(map, values[i], -1, NULL);
+           msSLDApplySLD(map, values[i], -1, NULL, NULL);
          else if (strcasecmp(names[i], "RULE") == 0)
            psRule = values[i];
          else if (strcasecmp(names[i], "SCALE") == 0)



More information about the mapserver-commits mailing list