1

I would like to use CQL in a URL call to return only a particular geometric type from a WFS that broadcasts multiple geometries. I have been going over this:

http://docs.geoserver.org/latest/en/user/filter/ecql_reference.html

and cannot see where it says "Here is how you build the URL," or "Here is how you return only geometries matching a given type."

Here is a non-working call that expresses what I want to do on a GeoServer instance with a WFS 1.0.0 feed:

http://server/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName=dataset:layer&cql_filter=(geometry='Point')AND(WITHIN(geometry,POLYGON((10.00 20.00,...))))

This call works:

http://server/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName=dataset:layer&cql_filter=WITHIN(geometry,POLYGON((10.00 20.00,...)))

So all I need to do is add in the geometric type limiter.

My geometry token on GeoServer is geometry

I know how to do the geometric limitation using OGC XML, but I do not know how to add in the polygon WITHIN statement using OGC XML. So I would accept an answer that clearly defines how to construct the XML version of this same thing, or a CQL solution for the same. I tried a coarse bounding box:

<ogc Filter xmlns:ogc='http://www.opengis.net/ogc'>
    <ogc:And>
        <ogc:BBOX>
            <ogc:PropertyName>geometry</ogc:PropertyName>
            <gml:Box srsName="EPSG:4326">
                <gml:coordinates>10.0,20.0,30.0...</gml:coordinates>
            </gml:Box>
        </ogc:BBOX>
        ---other queries---

This ends up yielding:

Attempted to construct illegal filter - I don't understand the tag: gml:Box.
2

TL;DR; You need to use the geometryType function e.g.

CQL_FILTER=geometryType(the_geom)='MultiPolygon'&

Longer Explanation

As you found on the ECQL page there is no way to directly get hold of the geometry type in ECQL, but GeoServer provides additional functions that can be called in a filter (either CQL or OGC) which includes a number of geometry functions including GeometryType:

name: geometryType
input: geometry:Geometry
Returns the type of the geometry as a string. May be Point, MultiPoint, LineString, LinearRing, MultiLineString, Polygon, MultiPolygon, GeometryCollection

This is the function you need to solve your problem, you may also find other helpful hints for dealing with mixed geometries on this page.

Bonus Answer

Your bbox query should be:

<wfs:Query typeName="topp:states">
    <wfs:PropertyName>topp:STATE_NAME</wfs:PropertyName>
    <wfs:PropertyName>topp:PERSONS</wfs:PropertyName>
    <ogc:Filter>
      <ogc:BBOX>
        <ogc:PropertyName>the_geom</ogc:PropertyName>
        <gml:Envelope srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
           <gml:lowerCorner>-75.102613 40.212597</gml:lowerCorner>
           <gml:upperCorner>-72.361859 41.512517</gml:upperCorner>
        </gml:Envelope>
      </ogc:BBOX>
   </ogc:Filter>
  </wfs:Query>

Which can be found in the helpful demos section of the GeoServer home page (look for WFS_getFeatureBBOX*.xml in the drop down menu).

  • This is a great answer and the CQL portion works for me. However the OGC BBOX query gives me java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 Index 0, Size: 0 - While this isn't the end of the world I believe that WFS queries if sent as POST need to be in OGC XML format, so it would be helpful if I could figure out why this part isn't working. – auslander Jun 28 '17 at 16:23
  • are you using wfs 1.x or 2.x? check out the demos for examples of each version (which changed) – Ian Turton Jun 28 '17 at 16:26
  • Hi, wfs 1.0.0. I'll take a look. – auslander Jun 28 '17 at 16:29
  • So it turns out that WFS 1.0.0 supports the gml:Box syntax I was using in the example. However it puts it all in wfs:Query tags. How would I put all that in a URL GET request? Am I missing the `<wfs:Query>' tag in the URL? – auslander Jun 28 '17 at 16:49

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.