[mapserver-commits] r10635 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Tue Oct 19 20:31:47 EDT 2010


Author: warmerdam
Date: 2010-10-19 17:31:47 -0700 (Tue, 19 Oct 2010)
New Revision: 10635

Modified:
   trunk/mapserver/mapwfs.c
Log:
implement support for maxfeatures and startindex for template/ogr resultsets by trimming the resultcache (#3570)

Modified: trunk/mapserver/mapwfs.c
===================================================================
--- trunk/mapserver/mapwfs.c	2010-10-20 00:31:00 UTC (rev 10634)
+++ trunk/mapserver/mapwfs.c	2010-10-20 00:31:47 UTC (rev 10635)
@@ -2501,14 +2501,54 @@
     }
     else 
     {
+        int to_allow = maxfeatures, to_skip = startindex-1;
         mapservObj *mapserv = msAllocMapServObj();
 
+        /* Setup dummy mapserv object */
         mapserv->sendheaders = MS_TRUE;
         mapserv->map = map;
         msFreeCgiObj(mapserv->request);
         mapserv->request = req;
         map->querymap.status = MS_FALSE;
 
+        /* trim the query result(s) if maxfeatures or startindex set. */
+        for( j=0; j < map->numlayers; j++ ) {
+            layerObj *lp = GET_LAYER(map, j);
+            if (lp->resultcache && lp->resultcache->numresults > 0)
+            {
+                if( to_skip > 0 && lp->resultcache->numresults < to_skip )
+                {
+                    to_skip -= lp->resultcache->numresults;
+                    lp->resultcache->numresults = 0;
+                }
+                else if( to_skip > 0 )
+                {
+                    memmove( lp->resultcache->results + 0,
+                             lp->resultcache->results + to_skip, 
+                             sizeof(resultCacheMemberObj) * (lp->resultcache->numresults - to_skip) );
+                    lp->resultcache->numresults -= to_skip;
+                    to_skip = 0;
+                }
+
+                if( maxfeatures > 0 )
+                {
+                    if( lp->resultcache->numresults > to_allow )
+                    {
+                        lp->resultcache->numresults = to_allow;
+                        to_allow = 0;
+                    }
+                    else 
+                    {
+                        to_allow -= lp->resultcache->numresults;
+                        if( to_allow < 0 )
+                            to_allow = 0;
+
+                        lp->resultcache->numresults = 0;
+                    }
+                }
+            }
+        }
+
         status = msReturnTemplateQuery( mapserv, psFormat->name, NULL );
 
         mapserv->request = NULL;



More information about the mapserver-commits mailing list