Opened 14 years ago

Closed 14 years ago

#2564 closed defect (fixed)

Filter Encoding: Modify DWithin definition

Reported by: assefa Owned by: assefa
Priority: normal Milestone: 5.2 release
Component: WFS Server Version: unspecified
Severity: normal Keywords:
Cc: pramsey@…, bartvde@…, tomkralidis


Currently DWithin is implemented using geos within functionality where the query shape is a buffered copy of the original shape. Same for within. My interpretation of the within/dwithin operator looking at the specs "simple feature specification for sql" was that the feature should be totally contained. If that is not the case, It can easily be changes to use the distance geos operator.

But this interpretation might be wrong and expected behavior would be more like and

Change History (9)

comment:1 by assefa, 14 years ago

Keywords: tomkralidis added

We had this discussion in bug #2105 ( and that was what was implemented.

Do we change it for 5.2 to be similar to within_distance?

comment:2 by pramsey, 14 years ago

I'm checking with PeterV on the origins of his BNF interpretation... I can't find it in the Cat1 or Cat2 docs. (I can find DWITHIN, but no explanation of semantics).

comment:3 by bartvde, 14 years ago

The following works for me to fix this:

--- mapquery.c.orig     2008-03-28 10:19:09.000000000 +0100
+++ mapquery.c  2008-03-28 10:19:37.000000000 +0100
@@ -1304,7 +1304,7 @@

           case MS_GEOS_WITHIN:
-            status = msGEOSWithin(&shape, selectshape);
+            status = (msGEOSDistance(&shape, selectshape) <= 0);
             if (status != MS_TRUE && status != MS_FALSE)
               status = MS_FALSE;

comment:4 by pramsey, 14 years ago

From Peter Vretanos <pvretano at cubewerx dot com>, the editor of the Filter specification document. Apparently DWithin was never really clearly defined, but he polled the rest of the working group and got:

I raised the issue of DWithin with:

1) Doug Nebert
2) The ISO/OGC WFS/FES Editing Committee

and the answers I got where:

Doug: DWithin(A,B,D) = Distance(A,B) < D

ISO EC: DWithin(A,B,D) = Within(Buffer(A,D),B)

so the filter specification will be Within(Buffer(A,D),B) 
since this seems to be the consensus of the members of the 
ISO editing committee.

If you need "Distance(A,B)<D" you can always define a 
function in V2.0 of the WFS to do this.  You can either 
use the Function element from Filter or define a stored 

If this is still an issue for you, I would be happy to 
raise the issue again with the ISO EC since there is 
still one more opportunity (before we release) the 

comment:5 by assefa, 14 years ago

Cc: tomkralidis added
Owner: changed from mapserverbugs to assefa
Status: newassigned


Thanks for following on this.

We sill have the opportunity before the 5.2 release to modify the current DWITHIN implementation to fit the Distance(A,B) < D model. At this point, for me the decision is more based on which way of doing things is more intuitive to the user and more useful. I am inclined at this point to says that Distance(A,B) < D would be a way to go. Tom, what would be your opinion on this? Any objections to modify the behaviour?

comment:6 by tomkralidis, 14 years ago

Keywords: tomkralidis removed

How does GeoServer do it? With the GeoAPI way (sorry, I'm not familiar with GeoServer innards)? I would see this as important in terms of semantic interpretation and how clients apply filters to WFS instances.

Having said this, I would tend to agree with Assefa in terms of intuitiveness. At the same time, if there is consensus at the ISO EC for the "other" way, do we, in MapServer, define DWithin as a SpatialOperator, or as a FunctionName specific to MapServer?

Don't mean to split hairs, but just want to pass on some food for thought. Personally, I would go with defining DWithin as a SpatialOperator per Distance(A,B) < D.

comment:7 by bartvde, 14 years ago

I agree with Tom, I would also go for defining DWithin as a SpatialOperator per Distance(A,B) < D.

Are we gonna do this before 5.2?

comment:8 by assefa, 14 years ago

Bart, this would be done before the 5.2 release.

comment:9 by assefa, 14 years ago

Resolution: fixed
Status: assignedclosed

changes committed in revision r7696.

Note: See TracTickets for help on using tickets.