2

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>
2

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".

  • "Intersects" worked like a charm. I tried it before and it didn't work. Maybe it was a caching issue with the script in my browser. Thanks. – JavaScript_Guru Aug 27 '14 at 19:20
1

Have you tried using Intersects or Overlaps?

Here are examples:

http://mapserver.org/ogc/filter_encoding.html#currently-supported-features https://wiki.state.ma.us/confluence/display/massgis/GeoServer+-+WFS+-+Filter+-+Overlaps

  • Yes, but neither returns any results when I use them, which seems odd to me. Only "Within" and "Crosses" return any results at all. I'll edit my question with the xml filter I'm using. – JavaScript_Guru Aug 27 '14 at 17:50
  • Yes, that is odd. Curious, does your geometryString contain the full polygon shape, meaning the first coordinate and last coordinate are the same? – evv_gis Aug 27 '14 at 18:03
  • I believe so. Here's an example: <gml:coordinates>3249612.4723581783,1578059.9225187912 3248959.3270610147,1578053.852474625 3248950.9266578197,1578958.9334702457 3249604.0499165086,1578965.0033096005 3249612.4723581783,1578059.9225187912</gml:coordinates> – JavaScript_Guru Aug 27 '14 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.