Permalink
Browse files

WFS SortBy support for OGR layers: include WHERE clause (when availab…

…le) to speed-up queries since OGR SQLite driver does not yet support fast attribute filter on SELECT result layers (#4878)
  • Loading branch information...
rouault committed Mar 5, 2014
1 parent 05c1a77 commit 1c30b21b7f5affa789dd9846c859d2e4ccb336da
Showing with 19 additions and 8 deletions.
  1. +19 −8 mapogr.cpp
View
@@ -1358,6 +1358,12 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect,
"msOGRFileWhichShapes()");
return(MS_FAILURE);
}
+
+ char* pszOGRFilter = NULL;
+ char* pszMSFilter = NULL;
+ /* In case we have an odd filter combining both a OGR filter and MapServer */
+ /* filter, then separate things */
+ msOGRSplitFilter(layer, &pszOGRFilter, &pszMSFilter);
/* Apply sortBy */
if( layer->sortBy.nProperties > 0 ) {
@@ -1403,7 +1409,15 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect,
}
pszLayerDef = msStringConcatenate(pszLayerDef, " FROM \"");
pszLayerDef = msStringConcatenate(pszLayerDef, OGR_FD_GetName(OGR_L_GetLayerDefn(psInfo->hLayer)));
- pszLayerDef = msStringConcatenate(pszLayerDef, "\" ORDER BY ");
+ pszLayerDef = msStringConcatenate(pszLayerDef, "\"");
+ if( pszOGRFilter != NULL )
+ {
+ pszLayerDef = msStringConcatenate(pszLayerDef, " WHERE ");
+ pszLayerDef = msStringConcatenate(pszLayerDef, pszOGRFilter);
+ msFree(pszOGRFilter);
+ pszOGRFilter = NULL;
+ }
+ pszLayerDef = msStringConcatenate(pszLayerDef, " ORDER BY ");
}
pszLayerDef = msStringConcatenate(pszLayerDef, strOrderBy);
@@ -1427,6 +1441,8 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect,
"msOGRFileWhichShapes()",
pszLayerDef, CPLGetLastErrorMsg() );
msFree(pszLayerDef);
+ msFree(pszOGRFilter);
+ msFree(pszMSFilter);
return MS_FAILURE;
}
msFree(pszLayerDef);
@@ -1492,13 +1508,8 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect,
* keyword in the filter string. Otherwise, ensure the attribute
* filter is clear.
* ------------------------------------------------------------------ */
-
- char* pszOGRFilter = NULL;
- char* pszMSFilter = NULL;
- /* In case we have an odd filter combining both a OGR filter and MapServer */
- /* filter, then separate things */
- msOGRSplitFilter(layer, &pszOGRFilter, &pszMSFilter);
- if( pszOGRFilter != NULL && pszMSFilter != NULL ) {
+
+ if( pszMSFilter != NULL ) {
msLoadExpressionString(&layer->filter, pszMSFilter);
if(layer->filter.type == MS_EXPRESSION) msTokenizeExpression(&(layer->filter), layer->items, &(layer->numitems));
}

0 comments on commit 1c30b21

Please sign in to comment.