Skip to content

Commit

Permalink
mapmssql2008.c: honour "wfs_use_default_extent_for_getfeature" "false…
Browse files Browse the repository at this point in the history
…" LAYER.METADATA (fixes #5994)
  • Loading branch information
rouault committed Feb 24, 2020
1 parent 6df2d2f commit f9ca113
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
48 changes: 30 additions & 18 deletions mapmssql2008.c
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,8 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string)

char *pos_from, *pos_ftab, *pos_space, *pos_paren;
int hasFilter = MS_FALSE;
const rectObj rectInvalid = MS_INIT_INVALID_RECT;
const int bIsValidRect = memcmp(&rect, &rectInvalid, sizeof(rect)) != 0;

layerinfo = getMSSQL2008LayerInfo(layer);

Expand Down Expand Up @@ -1519,16 +1521,18 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string)
hasFilter = MS_TRUE;
}

/* adding spatial filter */
if (hasFilter == MS_FALSE)
query = msStringConcatenate(query, " WHERE ");
else
query = msStringConcatenate(query, " AND ");
if( bIsValidRect ) {
/* adding spatial filter */
if (hasFilter == MS_FALSE)
query = msStringConcatenate(query, " WHERE ");
else
query = msStringConcatenate(query, " AND ");

query = msStringConcatenate(query, layerinfo->geom_column);
query = msStringConcatenate(query, ".STIntersects(");
query = msStringConcatenate(query, box3d);
query = msStringConcatenate(query, ") = 1 ");
query = msStringConcatenate(query, layerinfo->geom_column);
query = msStringConcatenate(query, ".STIntersects(");
query = msStringConcatenate(query, box3d);
query = msStringConcatenate(query, ") = 1 ");
}

if (paging_query) {
paging_query = msStringConcatenate(paging_query, query);
Expand Down Expand Up @@ -2515,6 +2519,8 @@ int msMSSQL2008LayerGetShapeCount(layerObj *layer, rectObj rect, projectionObj *
SQLLEN retLen;
SQLRETURN rc;
int hasFilter = MS_FALSE;
const rectObj rectInvalid = MS_INIT_INVALID_RECT;
const int bIsValidRect = memcmp(&rect, &rectInvalid, sizeof(rect)) != 0;

rectObj searchrectInLayerProj = rect;

Expand Down Expand Up @@ -2590,16 +2596,22 @@ int msMSSQL2008LayerGetShapeCount(layerObj *layer, rectObj rect, projectionObj *
hasFilter = MS_TRUE;
}

/* adding spatial filter */
if (hasFilter == MS_FALSE)
query = msStringConcatenate(query, " WHERE ");
else
query = msStringConcatenate(query, " AND ");
if( bIsValidRect ) {
/* adding spatial filter */
if (hasFilter == MS_FALSE)
query = msStringConcatenate(query, " WHERE ");
else
query = msStringConcatenate(query, " AND ");

query = msStringConcatenate(query, layerinfo->geom_column);
query = msStringConcatenate(query, ".MakeValid().STIntersects(");
query = msStringConcatenate(query, box3d);
query = msStringConcatenate(query, ") = 1 ");
query = msStringConcatenate(query, layerinfo->geom_column);
query = msStringConcatenate(query, ".STIntersects(");
query = msStringConcatenate(query, box3d);
query = msStringConcatenate(query, ") = 1 ");
}

if (layer->debug) {
msDebug("query:%s\n", query);
}

if (!executeSQL(layerinfo->conn, query)) {
msFree(query);
Expand Down
3 changes: 2 additions & 1 deletion mapogcfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ int FLTLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map,
pszUseDefaultExtent = msOWSLookupMetadata(&(lp->metadata), "F",
"use_default_extent_for_getfeature");
if( pszUseDefaultExtent && !CSLTestBoolean(pszUseDefaultExtent) &&
lp->connectiontype == MS_OGR )
(lp->connectiontype == MS_OGR ||
((lp->connectiontype == MS_PLUGIN) && (strstr(lp->plugin_library,"msplugin_mssql2008") != NULL))) )
{
const rectObj rectInvalid = MS_INIT_INVALID_RECT;
rect = rectInvalid;
Expand Down
1 change: 1 addition & 0 deletions msautotest/mssql/wfs_mssql.map
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ MAP
METADATA
"gml_include_items" "all"
"gml_types" "auto"
"wfs_use_default_extent_for_getfeature" "false"
END
END

Expand Down

0 comments on commit f9ca113

Please sign in to comment.