[mapserver-commits] r9931 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Wed Mar 10 17:11:31 EST 2010


Author: assefa
Date: 2010-03-10 17:11:31 -0500 (Wed, 10 Mar 2010)
New Revision: 9931

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapdraw.c
   trunk/mapserver/mapfile.c
   trunk/mapserver/mapgml.c
   trunk/mapserver/mapogcfilter.c
   trunk/mapserver/mappostgis.c
   trunk/mapserver/mapquery.c
   trunk/mapserver/mapserver.h
   trunk/mapserver/mapwfs.c
Log:
Correct one pass query problems and OGC filter query (#3305)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2010-03-10 14:48:22 UTC (rev 9930)
+++ trunk/mapserver/HISTORY.TXT	2010-03-10 22:11:31 UTC (rev 9931)
@@ -14,6 +14,8 @@
 Current Version (SVN trunk):
 ----------------------------
 
+- Correct one pass query problems and OGC filter query (#3305)
+
 - Fixed msMSSQL2008CloseConnection() to free the statement handle properly (#3244)
 
 - Fixed the query handling with the MSSQL2008 driver (#3058)

Modified: trunk/mapserver/mapdraw.c
===================================================================
--- trunk/mapserver/mapdraw.c	2010-03-10 14:48:22 UTC (rev 9930)
+++ trunk/mapserver/mapdraw.c	2010-03-10 22:11:31 UTC (rev 9931)
@@ -1216,7 +1216,10 @@
   msInitShape(&shape);
 
   for(i=0; i<layer->resultcache->numresults; i++) {
-    status = msLayerResultsGetShape(layer, &shape, layer->resultcache->results[i].tileindex, layer->resultcache->results[i].shapeindex);
+    if(layer->resultcache->usegetshape) 
+      status = msLayerGetShape(layer, &shape, layer->resultcache->results[i].tileindex, layer->resultcache->results[i].shapeindex);
+    else
+      status = msLayerResultsGetShape(layer, &shape, layer->resultcache->results[i].tileindex, layer->resultcache->results[i].shapeindex);
     if(status != MS_SUCCESS) {
         msFree(colorbuffer);
         msFree(mindistancebuffer);

Modified: trunk/mapserver/mapfile.c
===================================================================
--- trunk/mapserver/mapfile.c	2010-03-10 14:48:22 UTC (rev 9930)
+++ trunk/mapserver/mapfile.c	2010-03-10 22:11:31 UTC (rev 9931)
@@ -5729,3 +5729,14 @@
   }
 }
 
+void initResultCache(resultCacheObj *resultcache)
+{
+    if (resultcache)
+    {
+        resultcache->results = NULL;
+        resultcache->numresults = 0;
+        resultcache->cachesize = 0;
+        resultcache->bounds.minx = resultcache->bounds.miny = resultcache->bounds.maxx = resultcache->bounds.maxy = -1;
+        resultcache->usegetshape = MS_FALSE;
+    }
+}

Modified: trunk/mapserver/mapgml.c
===================================================================
--- trunk/mapserver/mapgml.c	2010-03-10 14:48:22 UTC (rev 9930)
+++ trunk/mapserver/mapgml.c	2010-03-10 22:11:31 UTC (rev 9931)
@@ -1519,7 +1519,10 @@
             continue;
         }
 
-        status = msLayerResultsGetShape(lp, &shape, lp->resultcache->results[j].tileindex, lp->resultcache->results[j].shapeindex);
+        if(lp->resultcache->usegetshape)
+           status = msLayerGetShape(lp, &shape, lp->resultcache->results[j].tileindex, lp->resultcache->results[j].shapeindex);
+        else
+          status = msLayerResultsGetShape(lp, &shape, lp->resultcache->results[j].tileindex, lp->resultcache->results[j].shapeindex);        
         if(status != MS_SUCCESS) 
             return(status);
 

Modified: trunk/mapserver/mapogcfilter.c
===================================================================
--- trunk/mapserver/mapogcfilter.c	2010-03-10 14:48:22 UTC (rev 9930)
+++ trunk/mapserver/mapogcfilter.c	2010-03-10 22:11:31 UTC (rev 9931)
@@ -599,15 +599,11 @@
 
     psLayer->resultcache = (resultCacheObj *)malloc(sizeof(resultCacheObj));
 
-    psLayer->resultcache->results = NULL;
-    psLayer->resultcache->numresults =  0;
-    psLayer->resultcache->cachesize = 0;
-    psLayer->resultcache->bounds.minx = -1;
-    psLayer->resultcache->bounds.miny = -1;
-    psLayer->resultcache->bounds.maxx = -1;
-    psLayer->resultcache->bounds.maxy = -1;
+    initResultCache(psLayer->resultcache); 
+    /*this will force the queries to retrive the shapes using 
+     their unique id #3305*/
+    psLayer->resultcache->usegetshape = MS_TRUE;
 
-
     status = msLayerOpen(psLayer);
     if (status != MS_SUCCESS) 
       return;
@@ -627,7 +623,7 @@
     for (i=0; i<nSize; i++)
     {
         msInitShape(&shape);
-        status = msLayerResultsGetShape(psLayer, &shape, -1, anValues[i]);
+        status = msLayerGetShape(psLayer, &shape, -1, anValues[i]);
 
         if (status != MS_SUCCESS)
           nClassIndex = -1;

Modified: trunk/mapserver/mappostgis.c
===================================================================
--- trunk/mapserver/mappostgis.c	2010-03-10 14:48:22 UTC (rev 9930)
+++ trunk/mapserver/mappostgis.c	2010-03-10 22:11:31 UTC (rev 9931)
@@ -1382,7 +1382,7 @@
 
 }
 
-int msPostGISReadShape(layerObj *layer, shapeObj *shape, int random) {
+int msPostGISReadShape(layerObj *layer, shapeObj *shape) {
 
     char *wkbstr = NULL;
     unsigned char *wkb = NULL;
@@ -1480,26 +1480,21 @@
             }
         }
         
-        if( random ) {
-            /* t is the geometry, t+1 is the uid */
-            tmp = PQgetvalue(layerinfo->pgresult, layerinfo->rownum, t + 1);
-            if( tmp ) {
-                uid = strtol( tmp, NULL, 10 );
-            }
-            else {
-                uid = 0;
-            }
-            if( layer->debug > 4 ) {
-                msDebug("msPostGISReadShape: Setting shape->index = %d\n", uid);
-            }
-            shape->index = uid;
-        } else {
-            if( layer->debug > 4 ) {
-                msDebug("msPostGISReadShape: Setting shape->index = %d\n", layerinfo->rownum);
-            }
-            shape->index = layerinfo->rownum;
+        /* t is the geometry, t+1 is the uid */
+        tmp = PQgetvalue(layerinfo->pgresult, layerinfo->rownum, t + 1);
+        if( tmp ) {
+            uid = strtol( tmp, NULL, 10 );
         }
-
+        else {
+            uid = 0;
+        }
+        if( layer->debug > 4 ) {
+            msDebug("msPostGISReadShape: Setting shape->index = %d\n", uid);
+            msDebug("msPostGISReadShape: Setting shape->tileindex = %d\n", layerinfo->rownum);
+        }
+        shape->index = uid;
+        shape->tileindex = layerinfo->rownum;
+        
         if( layer->debug > 2 ) {
             msDebug("msPostGISReadShape: [index] %d\n",  shape->index);
         }
@@ -1886,7 +1881,7 @@
         if (layerinfo->rownum < PQntuples(layerinfo->pgresult)) {
             int rv;
             /* Retrieve this shape, cursor access mode. */
-            rv = msPostGISReadShape(layer, shape, 0);
+            rv = msPostGISReadShape(layer, shape);
             if( shape->type != MS_SHAPE_NULL ) {
                 (layerinfo->rownum)++; /* move to next shape */
                 return MS_SUCCESS;
@@ -1931,6 +1926,11 @@
         msDebug("msPostGISLayerResultsGetShape called for record = %i\n", record);
     }
 
+    if( tile < 0 ) {
+        msDebug("msPostGISLayerResultsGetShape called for record = %i\n", record);
+        return msPostGISLayerResultsGetShape(layer, shape, tile, record);
+    }
+
     layerinfo = (msPostGISLayerInfo*) layer->layerinfo;
 
     /* Check the validity of the open result. */
@@ -1953,21 +1953,21 @@
     }
 
     /* Check the validity of the requested record number. */
-    if( record >= PQntuples(pgresult) ) {
-        msDebug("msPostGISLayerResultsGetShape got record request (%d) but only has %d tuples.\n", record, PQntuples(pgresult));
+    if( tile >= PQntuples(pgresult) ) {
+        msDebug("msPostGISLayerResultsGetShape got request for (%d) but only has %d tuples.\n", tile, PQntuples(pgresult));
         msSetError( MS_MISCERR,
                     "Got request larger than result set.",
                     "msPostGISLayerResultsGetShape()");
         return MS_FAILURE;
     }
 
-    layerinfo->rownum = record; /* Only return one result. */
+    layerinfo->rownum = tile; /* Only return one result. */
 
     /* We don't know the shape type until we read the geometry. */
     shape->type = MS_SHAPE_NULL;
 
 	/* Return the shape, cursor access mode. */
-    result = msPostGISReadShape(layer, shape, 0);
+    result = msPostGISReadShape(layer, shape);
 
     return (shape->type == MS_SHAPE_NULL) ? MS_FAILURE : MS_SUCCESS;
 #else
@@ -2054,7 +2054,7 @@
 
     if (num_tuples > 0) {
         /* Get shape in random access mode. */
-        result = msPostGISReadShape(layer, shape, 1);
+        result = msPostGISReadShape(layer, shape);
     }
 
     return (shape->type == MS_SHAPE_NULL) ? MS_FAILURE : ( (num_tuples > 0) ? MS_SUCCESS : MS_DONE );

Modified: trunk/mapserver/mapquery.c
===================================================================
--- trunk/mapserver/mapquery.c	2010-03-10 14:48:22 UTC (rev 9930)
+++ trunk/mapserver/mapquery.c	2010-03-10 22:11:31 UTC (rev 9931)
@@ -364,9 +364,7 @@
 
   if(map->query.clear_resultcache || lp->resultcache == NULL) {
     lp->resultcache = (resultCacheObj *)malloc(sizeof(resultCacheObj)); /* allocate and initialize the result cache */
-    lp->resultcache->results = NULL;
-    lp->resultcache->numresults = lp->resultcache->cachesize = 0;
-    lp->resultcache->bounds.minx = lp->resultcache->bounds.miny = lp->resultcache->bounds.maxx = lp->resultcache->bounds.maxy = -1;
+    initResultCache( lp->resultcache);
   }
 
   msInitShape(&shape);
@@ -523,9 +521,7 @@
   }
 
   lp->resultcache = (resultCacheObj *)malloc(sizeof(resultCacheObj)); /* allocate and initialize the result cache */
-  lp->resultcache->results = NULL;
-  lp->resultcache->numresults = lp->resultcache->cachesize = 0;
-  lp->resultcache->bounds.minx = lp->resultcache->bounds.miny = lp->resultcache->bounds.maxx = lp->resultcache->bounds.maxy = -1;
+  initResultCache( lp->resultcache);
   
   nclasses = 0;
   classgroup = NULL;
@@ -676,9 +672,7 @@
     }
 
     lp->resultcache = (resultCacheObj *)malloc(sizeof(resultCacheObj)); /* allocate and initialize the result cache */
-    lp->resultcache->results = NULL;
-    lp->resultcache->numresults = lp->resultcache->cachesize = 0;
-    lp->resultcache->bounds.minx = lp->resultcache->bounds.miny = lp->resultcache->bounds.maxx = lp->resultcache->bounds.maxy = -1;
+    initResultCache( lp->resultcache);
 
     nclasses = 0;
     classgroup = NULL;
@@ -910,9 +904,8 @@
 
       if(i == 0) {
 	lp->resultcache = (resultCacheObj *)malloc(sizeof(resultCacheObj)); /* allocate and initialize the result cache */
-	lp->resultcache->results = NULL;
-	lp->resultcache->numresults = lp->resultcache->cachesize = 0;
-	lp->resultcache->bounds.minx = lp->resultcache->bounds.miny = lp->resultcache->bounds.maxx = lp->resultcache->bounds.maxy = -1;    
+        initResultCache( lp->resultcache);
+
       }      
 
       nclasses = 0;
@@ -1169,9 +1162,7 @@
     }
 
     lp->resultcache = (resultCacheObj *)malloc(sizeof(resultCacheObj)); /* allocate and initialize the result cache */
-    lp->resultcache->results = NULL;
-    lp->resultcache->numresults = lp->resultcache->cachesize = 0;
-    lp->resultcache->bounds.minx = lp->resultcache->bounds.miny = lp->resultcache->bounds.maxx = lp->resultcache->bounds.maxy = -1;
+    initResultCache( lp->resultcache);
 
     nclasses = 0;
     classgroup = NULL;
@@ -1360,9 +1351,7 @@
     }
 
     lp->resultcache = (resultCacheObj *)malloc(sizeof(resultCacheObj)); /* allocate and initialize the result cache */
-    lp->resultcache->results = NULL;
-    lp->resultcache->numresults = lp->resultcache->cachesize = 0;
-    lp->resultcache->bounds.minx = lp->resultcache->bounds.miny = lp->resultcache->bounds.maxx = lp->resultcache->bounds.maxy = -1;
+    initResultCache( lp->resultcache);
 
     nclasses = 0;
     classgroup = NULL;
@@ -1575,10 +1564,8 @@
     if(status != MS_SUCCESS) return(MS_FAILURE);
 
     /* identify target shapes */
-    searchrect.minx = map->extent.minx;
-    searchrect.miny = map->extent.miny;
-    searchrect.maxx = map->extent.maxx;
-    searchrect.maxy = map->extent.maxy;
+    searchrect = qshape->bounds;
+
       
 #ifdef USE_PROJ
     if(lp->project && msProjectionsDiffer(&(lp->projection), &(map->projection)))
@@ -1596,9 +1583,7 @@
     }
 
     lp->resultcache = (resultCacheObj *)malloc(sizeof(resultCacheObj)); /* allocate and initialize the result cache */
-    lp->resultcache->results = NULL;
-    lp->resultcache->numresults = lp->resultcache->cachesize = 0;
-    lp->resultcache->bounds.minx = lp->resultcache->bounds.miny = lp->resultcache->bounds.maxx = lp->resultcache->bounds.maxy = -1;
+    initResultCache( lp->resultcache);
 
     classgroup = NULL;
     if (lp->classgroup && lp->numclasses > 0)

Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h	2010-03-10 14:48:22 UTC (rev 9930)
+++ trunk/mapserver/mapserver.h	2010-03-10 22:11:31 UTC (rev 9931)
@@ -1018,6 +1018,9 @@
 #ifdef SWIG
 %mutable;
 #endif /* SWIG */
+  
+  /*used to force the result retreiving to use getshape instead of resultgetshape*/
+  int usegetshape;
 
 } resultCacheObj;
 
@@ -1625,6 +1628,7 @@
 MS_DLL_EXPORT void initGrid( graticuleObj *pGraticule );
 MS_DLL_EXPORT void initWeb(webObj *web);
 MS_DLL_EXPORT void freeWeb(webObj *web);
+MS_DLL_EXPORT void initResultCache(resultCacheObj *resultcache);
 
 MS_DLL_EXPORT featureListNodeObjPtr insertFeatureList(featureListNodeObjPtr *list, shapeObj *shape);
 MS_DLL_EXPORT void freeFeatureList(featureListNodeObjPtr list);

Modified: trunk/mapserver/mapwfs.c
===================================================================
--- trunk/mapserver/mapwfs.c	2010-03-10 14:48:22 UTC (rev 9930)
+++ trunk/mapserver/mapwfs.c	2010-03-10 22:11:31 UTC (rev 9931)
@@ -1050,6 +1050,9 @@
   int nQueriedLayers=0;
   layerObj *lpQueried=NULL;
 
+  /*use msLayerGetShape instead of msLayerResultsGetShape of complex filter #3305*/
+  int bComplexFilter = MS_FALSE;
+
   /* Default filter is map extents */
   bbox = map->extent;
   
@@ -1552,6 +1555,20 @@
 	}
 	psNode = FLTParseFilterEncoding(paszFilter[i]);
 	
+        /*if we have a complex filter, make sure that paging is done at the gml output level
+          and not at the driver level #3305*/
+        bComplexFilter = (!FLTIsSimpleFilter(psNode));
+        if (bComplexFilter && nQueriedLayers == 1 && lpQueried &&
+            msLayerSupportsPaging(lpQueried) && 
+            (lpQueried->startindex > 0 && lpQueried->maxfeatures > 0))
+        {
+            startindex = lpQueried->startindex;
+            lpQueried->startindex = -1;
+
+            maxfeatures = lpQueried->maxfeatures;
+            lpQueried->maxfeatures = -1;
+        }
+
 	if (!psNode) {
 	  msSetError(MS_WFSERR, 
 		     "Invalid or Unsupported FILTER in GetFeature : %s", 
@@ -1575,7 +1592,7 @@
             }
         }
 
-        FLTFreeFilterEncodingNode( psNode );
+         FLTFreeFilterEncodingNode( psNode );
         psNode = NULL;
       }
 



More information about the mapserver-commits mailing list