Skip to content
Permalink
Browse files

Merge pull request #5967 from rouault/wfs_fix_matching_features

WFS: fix WFS 2.0 numberMatched computation, by opening temporary new connection(s)
  • Loading branch information
rouault committed Jan 14, 2020
2 parents 8cb8ee9 + cf64661 commit f34efe19223093d43c340f6ae88c452db6279200
Showing with 17 additions and 30 deletions.
  1. +4 −2 mapcopy.c
  2. +13 −28 mapwfs.c
@@ -1283,8 +1283,10 @@ int msCopyMap(mapObj *dst, mapObj *src)
return MS_FAILURE;
}

for (i = 0; i < dst->numlayers; i++) {
MS_COPYSTELEM(layerorder[i]);
if( src->layerorder ) {
for (i = 0; i < dst->numlayers; i++) {
MS_COPYSTELEM(layerorder[i]);
}
}
MS_COPYSTELEM(debug);
MS_COPYSTRING(dst->datapattern, src->datapattern);
@@ -3000,7 +3000,6 @@ static int msWFSComputeMatchingFeatures(mapObj *map,
int nWFSVersion)
{
int nMatchingFeatures = -1;
int j;

if( nWFSVersion >= OWS_2_0_0 )
{
@@ -3052,28 +3051,24 @@ static int msWFSComputeMatchingFeatures(mapObj *map,
if( pszComputeNumberMatched != NULL &&
strcasecmp(pszComputeNumberMatched, "true") == 0 )
{
resultCacheObj** saveResultCache = (resultCacheObj** )
msSmallMalloc( map->numlayers * sizeof(resultCacheObj*));

/* Save the result cache that contains the features that we want to */
/* emit in the response */
for(j=0; j<map->numlayers; j++) {
layerObj* lp = GET_LAYER(map, j);
saveResultCache[j] = lp->resultcache;
lp->resultcache = NULL;
int j;
mapObj* mapTmp = (mapObj*)msSmallCalloc(1, sizeof(mapObj));
initMap(mapTmp);
msCopyMap(mapTmp, map);

/* Resent layer paging */
/* Re-run the query but with no limit */
mapTmp->query.maxfeatures = -1;
mapTmp->query.startindex = -1;
mapTmp->query.only_cache_result_count = MS_TRUE;
for(j=0; j<mapTmp->numlayers; j++) {
layerObj* lp = GET_LAYER(mapTmp, j);
/* Reset layer paging */
lp->maxfeatures = -1;
lp->startindex = -1;
}

/* Re-run the query but with no limit */
map->query.maxfeatures = -1;
map->query.startindex = -1;
map->query.only_cache_result_count = MS_TRUE;

nMatchingFeatures = 0;
msWFSRetrieveFeatures(map,
msWFSRetrieveFeatures(mapTmp,
ows_request,
paramsObj,
pgmlinfo,
@@ -3089,17 +3084,7 @@ static int msWFSComputeMatchingFeatures(mapObj *map,
&nMatchingFeatures,
NULL);

/* Restore the original result cache */
for(j=0; j<map->numlayers; j++) {
layerObj* lp = GET_LAYER(map, j);
if(lp->resultcache) {
if(lp->resultcache->results) free(lp->resultcache->results);
free(lp->resultcache);
lp->resultcache = NULL;
}
lp->resultcache = saveResultCache[j];
}
msFree(saveResultCache);
msFreeMap(mapTmp);
}
}
}

0 comments on commit f34efe1

Please sign in to comment.
You can’t perform that action at this time.