Skip to content

Commit

Permalink
Merge branch 'fix_rfc91_ogr'
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Sep 20, 2014
2 parents 28d8be3 + 6a4d00e commit 47f7ba9
Show file tree
Hide file tree
Showing 3 changed files with 294 additions and 76 deletions.
68 changes: 47 additions & 21 deletions mapogcfiltercommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,9 @@ char *FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, layerO
char *pszTmp=NULL;
projectionObj sProjTmp;
rectObj sQueryRect;
shapeObj *psTmpShape=NULL, *psBufferShape=NULL;
shapeObj *psTmpShape=NULL;
int bBBoxQuery = 0;
int bAlreadyReprojected = 0;

if (psNode == NULL || lp == NULL)
return NULL;
Expand All @@ -441,26 +442,54 @@ char *FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, layerO
return NULL;

/* get the shape */
/* BBOX case: replace it with NOT DISJOINT. */
if(FLTIsBBoxFilter(psNode)) {
char szPolygon[512];
FLTGetBBOX(psNode, &sQueryRect);

if(lp->projection.numargs > 0) {
if (psNode->pszSRS)
msInitProjection(&sProjTmp);
if (psNode->pszSRS) {
/* Use the non EPSG variant since axis swapping is done in FLTDoAxisSwappingIfNecessary */
if (msLoadProjectionString(&sProjTmp, psNode->pszSRS) == 0) {
msProjectRect(&sProjTmp, &lp->projection, &sQueryRect);
snprintf(szPolygon, sizeof(szPolygon),
"POLYGON((%.18f %.18f,%.18f %.18f,%.18f %.18f,%.18f %.18f,%.18f %.18f))",
sQueryRect.minx, sQueryRect.miny,
sQueryRect.minx, sQueryRect.maxy,
sQueryRect.maxx, sQueryRect.maxy,
sQueryRect.maxx, sQueryRect.miny,
sQueryRect.minx, sQueryRect.miny);

psTmpShape = msShapeFromWKT(szPolygon);

/* This is a horrible hack to deal with world-extent requests and */
/* reprojection. msProjectRect() detects if reprojection from longlat to */
/* projected SRS, and in that case it transforms the bbox to -1e-15,-1e-15,1e15,1e15 */
/* to ensure that all features are returned */
/* Make wfs_200_cite_filter_bbox_world.xml and wfs_200_cite_postgis_bbox_world.xml pass */
if( fabs(sQueryRect.minx - -180.0) < 1e-5 &&
fabs(sQueryRect.miny - -90.0) < 1e-5 &&
fabs(sQueryRect.maxx - 180.0) < 1e-5 &&
fabs(sQueryRect.maxy - 90.0) < 1e-5 )
{
if(lp->projection.numargs > 0) {
if (psNode->pszSRS)
msInitProjection(&sProjTmp);
if (psNode->pszSRS) {
/* Use the non EPSG variant since axis swapping is done in FLTDoAxisSwappingIfNecessary */
if (msLoadProjectionString(&sProjTmp, psNode->pszSRS) == 0) {
msProjectRect(&sProjTmp, &lp->projection, &sQueryRect);
}
} else if (lp->map->projection.numargs > 0)
msProjectRect(&lp->map->projection, &lp->projection, &sQueryRect);
if (psNode->pszSRS)
msFreeProjection(&sProjTmp);
}
if( sQueryRect.minx <= -1e14 )
{
msFreeShape(psTmpShape);
msFree(psTmpShape);
psTmpShape = (shapeObj*) msSmallMalloc(sizeof(shapeObj));
msInitShape(psTmpShape);
msRectToPolygon(sQueryRect, psTmpShape);
bAlreadyReprojected = 1;
}
} else if (lp->map->projection.numargs > 0)
msProjectRect(&lp->map->projection, &lp->projection, &sQueryRect);
if (psNode->pszSRS)
msFreeProjection(&sProjTmp);
}
psTmpShape = (shapeObj *)msSmallMalloc(sizeof(shapeObj));
msInitShape(psTmpShape);
msRectToPolygon(sQueryRect, psTmpShape);

bBBoxQuery = 1;
} else {
/* other geos type operations */
Expand Down Expand Up @@ -488,7 +517,7 @@ char *FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, layerO
/*
** target is layer projection
*/
if(!bBBoxQuery && lp->projection.numargs > 0) {
if(!bAlreadyReprojected && lp->projection.numargs > 0) {
if (psNode->pszSRS)
msInitProjection(&sProjTmp);
if (psNode->pszSRS) {
Expand Down Expand Up @@ -519,10 +548,7 @@ char *FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, layerO
pszExpression = msStringConcatenate(pszExpression, "(");

/* geometry binding */
if (bBBoxQuery)
sprintf(szBuffer, "%s", "[shape]");
else
sprintf(szBuffer, "%s", "[shape]");
sprintf(szBuffer, "%s", "[shape]");
pszExpression = msStringConcatenate(pszExpression, szBuffer);
pszExpression = msStringConcatenate(pszExpression, ",");

Expand Down
Loading

0 comments on commit 47f7ba9

Please sign in to comment.