4

I am trying to construct a WFS request. I want to determine if a certain point is within a polygon. The point coordinates I want to send via the WFS request. The polygon is saved as a layer on my GeoServer. How does a WFS request like this look like.

My request looks like this, but I am getting an error:

http://myserver.com:8080/geoserver/mapicture/ows?service=WFS&version=2.0.0&request=GetFeature&typeName=mystore:dk_ger_nowater&cql_filter=INTERSECT(geom,%20POINT%20(55.689972%10.239258

The error says:

error on line 4 at column 160: xmlParseCharRef: invalid xmlChar value 16
1
  • Sorry, I answered before reading thoroughly your question. CQL_FILTER is usable with Geoserver but no other WFS server brand supports it so be careful if you plan to make an interoperable application. The main error is that the filter name is "Intersects", not "Intersect". I will edit my answer to show cql_filter option.
    – user30184
    Jun 2 '14 at 12:15
6

You can check within which polygon, if any, your point is by using Contains filter.

 <wfs:GetFeature service="WFS" version="1.0.0"
      outputFormat="GML2"
      xmlns:topp="http://www.openplans.org/topp"
      xmlns:wfs="http://www.opengis.net/wfs"
      xmlns="http://www.opengis.net/ogc"
      xmlns:gml="http://www.opengis.net/gml"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.opengis.net/wfs
                          http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd">
      <wfs:Query typeName="topp:states">
        <Filter>
          <Contains>
            <PropertyName>the_geom</PropertyName>
              <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
                <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
              </gml:Point>
            </Contains>
          </Filter>
      </wfs:Query>
    </wfs:GetFeature>

If you want to use http GET it gets quite ugly:

http://localhost:8080/geoserver/wfs?service=WFS&request=GetFeature&version=1.0.0&typeName=topp:states&outputFormat=GML2&FILTER=%3CFilter%20xmlns=%22http://www.opengis.net/ogc%22%20xmlns:gml=%22http://www.opengis.net/gml%22%3E%3CContains%3E%3CPropertyName%3Ethe_geom%3C/PropertyName%3E%3Cgml:Point%20srsName=%22EPSG:4326%22%3E%3Cgml:coordinates%3E-74.817265,40.5296504%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Contains%3E%3C/Filter%3E

GeoServer supports also CQL_FILTER vendor parameter. The previous point-in-polygon query could as well use the Intersects filter and the result will be the same as with Intersects

http://localhost:8080/geoserver/wfs?service=WFS&request=GetFeature&version=1.0.0&typeName=topp:states&outputFormat=GML2&CQL_FILTER=INTERSECTS%28the_geom,%20POINT%20%28-74.817265%2040.5296504%29%29

I recommend you to install GeoServer on your own computer. The user interface has rather many query and filter examples in the Demo - Demo requests section. Requests and filters appear in a text box and you can not only execute them but also edit them before which makes it easy for you to make and test your own requests.

1
  • Thanks for your answer. It works great. Also thanks for hint to the Geoserver demo request section. Never saw that before. I will check it out.
    – ustroetz
    Jun 2 '14 at 12:18

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.