I am having trouble using 'Intersect' filter on a WFS GetFeature query. Every query I make seems to return all features available in the queried layer (and not just the features intersecting the polygon I specify).

I used the topp:states layer from the publicly accessible demo Geoserver.

The POST request I made to the above server was:

<wfs:GetFeature xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.opengis.net/wfs"
    xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs"
    xmlns:ogc="http://www.opengis.net/ogc" service="WFS" version="1.0.0">
    <wfs:Query typeName="topp:states">
        <ogc:Filter>
            <ogc:Intersect>
                <ogc:PropertyName>the_geom</ogc:PropertyName>
                <gml:Polygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-106.86953585585587,42.627785135135127 -107.47663975975976,38.803030540540533 -105.29106570570572,35.342538288288281 -99.280737057057067,36.01035258258257 -98.4307915915916,41.413577327327317 -106.86953585585587,42.627785135135127</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>
            </ogc:Intersect>
        </ogc:Filter>
    </wfs:Query>
</wfs:GetFeature>

This is how the intersector polygon (in green) looks like in relation to the states:

Preview of how the intersector polygon looks w.r.t the states layer

As would be expected from the above diagram, I am hoping that the intersect query would return 7 states. Instead, what I get in the WFS response is all of the 50 states.

Am I doing something wrong in the WFS query?

I have already made sure that the polygon I used to intersect against is in the same SRS as the layer (EPSG 4326).

  • 3
    @user30184 Please, please, don't change the title so it contains the answer. That's something you should've learned when you were doing suggested edits – it's clearly conflicting with the intent of the author. – Nic Hartley Apr 23 '16 at 17:05
  • What would you suggest? I did not like the original because it may lead people to think that "Intersect" is a valid WFS filter. – user30184 Apr 23 '16 at 18:52
  • 1
    Reverted the edit and wrote an answer that shows that the same misspelling is also in the WFS 1.0.0 standard. – user30184 Apr 23 '16 at 19:49
up vote 8 down vote accepted

Try with intersects:

   <ogc:Intersects>
        ...
   </ogc:Intersects>

You are using WFS 1.0.0. That WFS version is using Filter Encoding Standard 1.0.0 http://portal.opengeospatial.org/files/?artifact_id=1171 and there is indeed a typo in the standard. On page 17 the schema for filter capabilities is defined as:

Spatial capabilities are encoded according to the following XML Schema fragment:
<xsd:complexType name="Spatial_CapabilitiesType">
<xsd:sequence>
<xsd:element name="Spatial_Operators"
type="ogc:Spatial_OperatorsType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Spatial_OperatorsType">
<xsd:choice maxOccurs="unbounded">
<xsd:element ref="ogc:Equals"/>
<xsd:element ref="ogc:Disjoint"/>
<xsd:element ref="ogc:Touches"/>
<xsd:element ref="ogc:Within"/>
<xsd:element ref="ogc:Overlaps"/>
<xsd:element ref="ogc:Crosses"/>
<xsd:element ref="ogc:Intersect"/>
<xsd:element ref="ogc:Contains"/>
<xsd:element ref="ogc:DWithin"/>
<xsd:element ref="ogc:Beyond"/>
<xsd:element ref="ogc:BBOX"/>
</xsd:choice>
</xsd:complexType>

However, the same standard defines on page 9:

The XML encoding for spatial operators is defined by the following XML Schema fragment:
<xsd:element name="Equals"
type="ogc:BinarySpatialOpType" substitutionGroup="ogc:spatialOps"/>
<xsd:element name="Intersects"
...

Thus the name of the operator is "Intersects" and that's how it must be used in filter. However, WFS 1.0.0 compliant servers must advertise the operator as "Intersect" because it is written so into the corresponding XML schema. You can also see that for example GeoServer follows the standard and request http://demo.opengeo.org/geoserver/wfs?service=wfs&version=1.0.0&request=getcapabilities returns

<ogc:Filter_Capabilities>
<ogc:Spatial_Capabilities>
<ogc:Spatial_Operators>
...
<ogc:Intersect/>
...

In later Filter Encoding standard versions this misspelling is corrected and for example http://demo.opengeo.org/geoserver/wfs?service=wfs&version=1.1.0&request=getcapabilities returns the operator name as

<ogc:SpatialOperator name="Intersects"/>
  • What a fantastic and detailed answer! I would love to mark this as the accepted answer but it feels wrong to take away points from @Azimo's answer, considering how quick the response was. What is SE etiquette in such cases? What would the right thing to do be? – balajeerc Apr 25 '16 at 6:34
  • Let it be as it is @Azimo deserves the honor. – user30184 Apr 25 '16 at 7:24

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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