[mapserver-commits] r11828 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Thu Jun 16 10:17:54 EDT 2011
Author: aboudreault
Date: 2011-06-16 07:17:54 -0700 (Thu, 16 Jun 2011)
New Revision: 11828
Modified:
trunk/mapserver/HISTORY.TXT
trunk/mapserver/mapdraw.c
trunk/mapserver/mapows.h
trunk/mapserver/mapwms.c
trunk/mapserver/mapwmslayer.c
Log:
Added WMS GetFeatureInfo Cascading (#3764)
Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT 2011-06-16 13:53:42 UTC (rev 11827)
+++ trunk/mapserver/HISTORY.TXT 2011-06-16 14:17:54 UTC (rev 11828)
@@ -15,6 +15,8 @@
Current Version (SVN trunk, 6.1-dev, future 6.2):
-------------------------------------------------
+- Added WMS GetFeatureInfo Cascading (#3764)
+
- Fixed png lib is not found on multiarch systems (#3921)
- Fixed PHP MapScript opacity property of StyleObj no longer works (#3920)
Modified: trunk/mapserver/mapdraw.c
===================================================================
--- trunk/mapserver/mapdraw.c 2011-06-16 13:53:42 UTC (rev 11827)
+++ trunk/mapserver/mapdraw.c 2011-06-16 14:17:54 UTC (rev 11828)
@@ -331,7 +331,7 @@
#ifdef USE_WMS_LYR
if(lp->connectiontype == MS_WMS) {
- if(msPrepareWMSLayerRequest(map->layerorder[i], map, lp, lastconnectiontype, &sLastWMSParams, pasOWSReqInfo, &numOWSRequests) == MS_FAILURE) {
+ if(msPrepareWMSLayerRequest(map->layerorder[i], map, lp, 1, lastconnectiontype, &sLastWMSParams, 0, 0, 0, NULL, pasOWSReqInfo, &numOWSRequests) == MS_FAILURE) {
msFreeWmsParamsObj(&sLastWMSParams);
msFreeImage(image);
msFree(pasOWSReqInfo);
@@ -1314,8 +1314,8 @@
msHTTPInitRequestObj(asReqInfo, 2);
- if ( msPrepareWMSLayerRequest(1, map, layer,
- 0, NULL,
+ if ( msPrepareWMSLayerRequest(1, map, layer, 1,
+ 0, NULL, 0, 0, 0, NULL,
asReqInfo, &numReq) == MS_FAILURE ||
msOWSExecuteRequests(asReqInfo, numReq, map, MS_TRUE) == MS_FAILURE )
{
Modified: trunk/mapserver/mapows.h
===================================================================
--- trunk/mapserver/mapows.h 2011-06-16 13:53:42 UTC (rev 11827)
+++ trunk/mapserver/mapows.h 2011-06-16 14:17:54 UTC (rev 11828)
@@ -382,8 +382,9 @@
void msFreeWmsParamsObj(wmsParamsObj *wmsparams);
int msPrepareWMSLayerRequest(int nLayerId, mapObj *map, layerObj *lp,
- enum MS_CONNECTION_TYPE lastconnectiontype,
+ int nRequestType, enum MS_CONNECTION_TYPE lastconnectiontype,
wmsParamsObj *psLastWMSParams,
+ int nClickX, int nClickY, int nFeatureCount, const char *pszInfoFormat,
httpRequestObj *pasReqInfo, int *numRequests);
int msDrawWMSLayerLow(int nLayerId, httpRequestObj *pasReqInfo,
int numRequests, mapObj *map, layerObj *lp,
@@ -391,10 +392,9 @@
MS_DLL_EXPORT char *msWMSGetFeatureInfoURL(mapObj *map, layerObj *lp,
int nClickX, int nClickY, int nFeatureCount,
const char *pszInfoFormat);
+int msWMSLayerFeatureInfo(mapObj *map, int nOWSLayers, int nClickX, int nClickY,
+ int nFeatureCount, const char *pszInfoFormat);
-
-
-
/*====================================================================
* mapwfs.c
*====================================================================*/
Modified: trunk/mapserver/mapwms.c
===================================================================
--- trunk/mapserver/mapwms.c 2011-06-16 13:53:42 UTC (rev 11827)
+++ trunk/mapserver/mapwms.c 2011-06-16 14:17:54 UTC (rev 11828)
@@ -3100,6 +3100,9 @@
int valid_format=MS_FALSE;
int format_found = MS_FALSE;
int use_bbox = MS_FALSE;
+ int wms_layer = MS_FALSE;
+ const char *wms_connection = NULL;
+ int numOWSLayers = 0;
encoding = msOWSLookupMetadata(&(map->web.metadata), "MO", "encoding");
@@ -3126,9 +3129,13 @@
(map->name && strcasecmp(map->name, layers[k]) == 0) ||
(GET_LAYER(map, j)->group && strcasecmp(GET_LAYER(map, j)->group, layers[k]) == 0)) &&
(msIntegerInArray(GET_LAYER(map, j)->index, ows_request->enabled_layers, ows_request->numlayers)) )
- {
- numlayers_found++;
- GET_LAYER(map, j)->status = MS_ON;
+ {
+ if (GET_LAYER(map, j)->connectiontype == MS_WMS) {
+ wms_layer = MS_TRUE;
+ wms_connection = GET_LAYER(map, j)->connection;
+ }
+ numlayers_found++;
+ GET_LAYER(map, j)->status = MS_ON;
}
}
}
@@ -3173,7 +3180,7 @@
}
}
-
+
if(numlayers_found == 0)
{
if (query_layer)
@@ -3196,16 +3203,33 @@
/* check if all layers selected are queryable. If not send an */
/* exception. */
/* -------------------------------------------------------------------- */
-
+
+ /* If a layer of type WMS was found... all layers have to be of that type and with the same connection */
for (i=0; i<map->numlayers; i++)
{
- if (GET_LAYER(map, i)->status == MS_ON && !msIsLayerQueryable(GET_LAYER(map, i)))
- {
- msSetError(MS_WMSERR, "Requested layer(s) are not queryable.", "msWMSFeatureInfo()");
- return msWMSException(map, nVersion, "LayerNotQueryable", wms_exception_format);
+ if (GET_LAYER(map, i)->status == MS_ON)
+ {
+ if (!msIsLayerQueryable(GET_LAYER(map, i)))
+ {
+ msSetError(MS_WMSERR, "Requested layer(s) are not queryable.", "msWMSFeatureInfo()");
+ return msWMSException(map, nVersion, "LayerNotQueryable", wms_exception_format);
+ }
+ else if (wms_layer == MS_TRUE)
+ {
+ if ( (GET_LAYER(map, i)->connectiontype != MS_WMS) || (strcasecmp(wms_connection, GET_LAYER(map, i)->connection) != 0) )
+ {
+ msSetError(MS_WMSERR, "Requested WMS layer(s) are not queryable: type or connection differ", "msWMSFeatureInfo()");
+ return msWMSException(map, nVersion, "LayerNotQueryable", wms_exception_format);
+ }
+ ++numOWSLayers;
+ }
}
}
+ /* It's a valid Cascading WMS GetFeatureInfo request */
+ if (wms_layer)
+ return msWMSLayerFeatureInfo(map, numOWSLayers, point.x, point.y, feature_count, info_format);
+
if( use_bbox == MS_FALSE ) {
if(point.x == -1.0 || point.y == -1.0) {
Modified: trunk/mapserver/mapwmslayer.c
===================================================================
--- trunk/mapserver/mapwmslayer.c 2011-06-16 13:53:42 UTC (rev 11827)
+++ trunk/mapserver/mapwmslayer.c 2011-06-16 14:17:54 UTC (rev 11828)
@@ -934,8 +934,9 @@
**********************************************************************/
int msPrepareWMSLayerRequest(int nLayerId, mapObj *map, layerObj *lp,
- enum MS_CONNECTION_TYPE lastconnectiontype,
+ int nRequestType, enum MS_CONNECTION_TYPE lastconnectiontype,
wmsParamsObj *psLastWMSParams,
+ int nClickX, int nClickY, int nFeatureCount, const char *pszInfoFormat,
httpRequestObj *pasReqInfo, int *numRequests)
{
#ifdef USE_WMS_LYR
@@ -963,9 +964,22 @@
* Build the request URL, this will also set layer projection and
* compute BBOX in that projection.
* ------------------------------------------------------------------ */
- if ( msBuildWMSLayerURL(map, lp, WMS_GETMAP,
- 0, 0, 0, NULL, &bbox, &bbox_width, &bbox_height,
- &sThisWMSParams) != MS_SUCCESS)
+
+
+ if (nRequestType == WMS_GETMAP &&
+ ( msBuildWMSLayerURL(map, lp, WMS_GETMAP,
+ 0, 0, 0, NULL, &bbox, &bbox_width, &bbox_height,
+ &sThisWMSParams) != MS_SUCCESS) )
+ {
+ /* an error was already reported. */
+ msFreeWmsParamsObj(&sThisWMSParams);
+ return MS_FAILURE;
+ }
+
+ else if (msBuildWMSLayerURL(map, lp, WMS_GETFEATUREINFO,
+ nClickX, nClickY, nFeatureCount, pszInfoFormat,
+ NULL, NULL, NULL,
+ &sThisWMSParams) == MS_FAILURE)
{
/* an error was already reported. */
msFreeWmsParamsObj(&sThisWMSParams);
@@ -976,12 +990,12 @@
* Check if the request is empty, perhaps due to reprojection problems
* or wms_extents restrictions.
* ------------------------------------------------------------------ */
- if( bbox_width == 0 || bbox_height == 0 )
+ if ((nRequestType == WMS_GETMAP) && (bbox_width == 0 || bbox_height == 0) )
{
msFreeWmsParamsObj(&sThisWMSParams);
return MS_SUCCESS; /* No overlap. */
}
-
+
/* ------------------------------------------------------------------
* Check if layer overlaps current view window (using wms_latlonboundingbox)
* ------------------------------------------------------------------ */
@@ -1324,9 +1338,10 @@
pszURL = NULL;
pasReqInfo[(*numRequests)].pszHTTPCookieData = pszHTTPCookieData;
pszHTTPCookieData = NULL;
- if( bCacheToDisk )
+ if( bCacheToDisk ) {
pasReqInfo[(*numRequests)].pszOutputFile =
- msTmpFile(map, map->mappath, NULL, "img.tmp");
+ msTmpFile(map, map->mappath, NULL, "wms.tmp");
+ }
else
pasReqInfo[(*numRequests)].pszOutputFile = NULL;
pasReqInfo[(*numRequests)].nStatus = 0;
@@ -1626,3 +1641,107 @@
}
+int msWMSLayerFeatureInfo(mapObj *map, int nOWSLayers, int nClickX, int nClickY,
+ int nFeatureCount, const char *pszInfoFormat)
+{
+#ifdef USE_WMS_LYR
+
+ msIOContext *context;
+
+ httpRequestObj *pasReqInfo;
+ wmsParamsObj sLastWMSParams;
+ int i, numReq = 0;
+
+ pasReqInfo = (httpRequestObj *)msSmallMalloc((nOWSLayers+1)*sizeof(httpRequestObj));
+ msHTTPInitRequestObj(pasReqInfo, nOWSLayers+1);
+ msInitWmsParamsObj(&sLastWMSParams);
+
+ /* Generate the http request */
+ for (i=0; i<map->numlayers; i++)
+ {
+ if (GET_LAYER(map,map->layerorder[i])->status == MS_ON)
+ {
+ if (msPrepareWMSLayerRequest(map->layerorder[i], map, GET_LAYER(map,map->layerorder[i]), WMS_GETFEATUREINFO,
+ MS_WMS, &sLastWMSParams,
+ nClickX, nClickY, nFeatureCount, pszInfoFormat,
+ pasReqInfo, &numReq) == MS_FAILURE)
+ {
+ msFreeWmsParamsObj(&sLastWMSParams);
+ msFree(pasReqInfo);
+ return MS_FAILURE;
+ }
+ }
+ }
+
+ if (msOWSExecuteRequests(pasReqInfo, numReq, map, MS_FALSE) == MS_FAILURE)
+ {
+ msHTTPFreeRequestObj(pasReqInfo, numReq);
+ msFree(pasReqInfo);
+ msFreeWmsParamsObj(&sLastWMSParams);
+ return MS_FAILURE;
+ }
+
+ context = msIO_getHandler( stdout );
+ if( context == NULL )
+ {
+ msHTTPFreeRequestObj(pasReqInfo, numReq);
+ msFree(pasReqInfo);
+ msFreeWmsParamsObj(&sLastWMSParams);
+ return MS_FAILURE;
+ }
+
+ msIO_printf("Content-type: %s%c%c",pasReqInfo[0].pszContentType, 10,10);
+
+ if( pasReqInfo[0].pszOutputFile )
+ {
+ FILE *fp;
+ char szBuf[MS_BUFFER_LENGTH];
+
+ fp = fopen(pasReqInfo[0].pszOutputFile, "r");
+ if (fp)
+ {
+ while(1)
+ {
+ size_t nSize;
+ nSize = fread(szBuf, sizeof(char), MS_BUFFER_LENGTH-1, fp);
+ if (nSize > 0)
+ msIO_contextWrite( context,
+ szBuf,
+ nSize);
+ if (nSize != MS_BUFFER_LENGTH-1)
+ break;
+ }
+ fclose(fp);
+ if (!map->debug)
+ unlink(pasReqInfo[0].pszOutputFile);
+ }
+ else
+ {
+ msSetError(MS_IOERR, "'%s'.",
+ "msWMSLayerFeatureInfo()", pasReqInfo[0].pszOutputFile);
+ return MS_FAILURE;
+ }
+ }
+ else
+ {
+ msIO_contextWrite( context,
+ pasReqInfo[0].result_data,
+ pasReqInfo[0].result_size );
+ }
+
+ msHTTPFreeRequestObj(pasReqInfo, numReq);
+ msFree(pasReqInfo);
+ msFreeWmsParamsObj(&sLastWMSParams);
+
+ return MS_SUCCESS;
+#else
+/* ------------------------------------------------------------------
+ * WMS CONNECTION Support not included...
+ * ------------------------------------------------------------------ */
+ msSetError(MS_WMSCONNERR, "WMS CLIENT CONNECTION support is not available.",
+ "msWMSLayerFeatureInfo()");
+ return(MS_FAILURE);
+
+#endif /* USE_WMS_LYR */
+
+}
More information about the mapserver-commits
mailing list