[GIS] WFS Spatial Operator Query – Crosses AND Within

javascriptopen-source-giswfsxml

I'm trying to query my wfs service with a polygon. I want the service to return both features that are inside the polygon and partially inside the polygon. However, when I use the "Within" spatial operator, I only get features that are completely inside. When I use the "Crosses" operator, I only get the features that are partially inside the polygon. I have tried using And/Or to query for features that are either one or the other, but WFS does not support multiple spatial operators in a query. It gives me this error:

"Unsupported filter – filter has more than one spatial operator."

Does anyone have an idea of how to get around this without sending two separate ajax requests to the service?

Here's an example that returns data with the "within" filter.

var xml = '<ogc:Filter xmlns="http://www.opengis.net/ogc">\n'
             +      '<ogc:Within>\n'
             +        '<ogc:PropertyName>Shape</ogc:PropertyName>\n'
             +        '<gml:Polygon>\n'
             +          '<gml:outerBoundaryIs>\n'
             +            '<gml:LinearRing>\n'
             +              '<gml:coordinates>' + queryObject.geometryString + '</gml:coordinates>\n'
             +            '</gml:LinearRing>\n'
             +          '</gml:outerBoundaryIs>\n'
             +        '</gml:Polygon>\n'
             +      '</ogc:Within>\n'

             +    '</ogc:Filter>\n'

Here's the capabilites of the wfs service:

<ogc:SpatialOperators>
<ogc:SpatialOperator name="BBOX"/>
<ogc:SpatialOperator name="Equals"/>
<ogc:SpatialOperator name="Disjoint"/>
<ogc:SpatialOperator name="Intersects"/>
<ogc:SpatialOperator name="Crosses"/>
<ogc:SpatialOperator name="Touches"/>
<ogc:SpatialOperator name="Within"/>
<ogc:SpatialOperator name="Contains"/>
<ogc:SpatialOperator name="Overlaps"/>
</ogc:SpatialOperators>

Best Answer

Here are two rectangles drawn on top of the map of the States.

enter image description here

This is WFS 1.0.0 filter with two Intersects combined with OR

<ogc:Filter>
<ogc:Or>
<ogc:Intersects>
<ogc:PropertyName>topp:the_geom</ogc:PropertyName>
<gml:Polygon>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates decimal="." cs="," ts=" ">-106.20615648060549,39.43168954588457 -106.20615648060549,42.000086140018915 -104.73069460737938,42.000086140018915 -104.73069460737938,39.43168954588457 -106.20615648060549,39.43168954588457</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</ogc:Intersects>
<ogc:Intersects>
<ogc:PropertyName>topp:the_geom</ogc:PropertyName>
<gml:Polygon>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates decimal="." cs="," ts=" ">-112.65447133396404,35.715711494796594 -112.65447133396404,38.06552114474929 -111.12436272469252,38.06552114474929 -111.12436272469252,35.715711494796594 -112.65447133396404,35.715711494796594</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</ogc:Intersects>
</ogc:Or>
</ogc:Filter>

Here you can see the result after sendind the request to WFS service at http://demo.opengeo.org/geoserver/wfs. The purple states are a new layer that was fetched from WFS.

enter image description here

Thus it is possible to include two spatial filters into one GetFeature request and it works at least with GeoServer WFS. Another thing is that in your case it is not necessary because Intersects filter should do what you want and select all features totally or partly inside the reference geometry. In other words Intersects is "Not Disjoint".