0

I am new to geoserver, I have setup the geoserver which provides the result in below format when I use the wfs service,

    "type": "FeatureCollection",
    "features": [{
            "type": "Feature",
            "id": "test.1",
            "geometry": {
                "type": "LineString",
                "coordinates": [[124.97017655, -34.80818888], [184.02247243, -62.90140597]]
            },
            "geometry_name": "geometry",
           "properties": {
                "id": "1",
                "abc_id": "1840350675",
                "name": "test",
              
            }
        },
        {
    "type": "FeatureCollection",
    "features": [{
            "type": "Feature",
            "id": "test.2",
            "geometry": {
                "type": "LineString",
                "coordinates": [[144.97017655, -34.80818888], [154.02247243, -65.90140597]]
            },
            "geometry_name": "geometry",
            "properties": {
                "id": "2",
                "abc_id": "1840350677",
                "name": "test1",
              
            }
        }
        }]

I want to perform the search on property 'name', where I should get the record with only name 'test'. after the multiple research, I found that I can use filter option with bbox to perform the search on geoserver with wfs as below, but I am not getting correct result after filter. Looks like it is not filtering with property name, can someone please suggest the way to perform the search with bbox + filter.

sharing query here which i amusing to filter the records on geoserver

    http://localhost:8888/geoserver/myproject/wfs?service=WFS&version=2.0.0&request=GetFeature&typeName=mv_testlayer&outputFormat=application/json&fo0rmat_options=callback:getJson&filter=(<Within><PropertyIsEqualTo><PropertyName>name</PropertyName><Literal>test</Literal></PropertyIsEqualTo><gml:Envelope><gml:lowerCorner>161.3776580 </gml:lowerCorner><gml:upperCorner>44.8219 -80.2693</gml:upperCorner></gml:Envelope></Within)
1
  • This has nothing to actually do with GeoServer, its a general WFS issue
    – Ian Turton
    Mar 15 at 9:58

1 Answer 1

1

The reason is this doesn't work is that the Geometry of a feature is not a property of the feature. Properties are (usually) simpler objects like numbers or strings of text. It also fails as you attempt to close the PropertyIsEqualTo tag with a /Within tag.

To understand filtering with 2.0.0 WFS servers you should at least glance at the Filter Encoding Specification (FES) where you will learn of the BBOX filter which is what you actually want:

The fes:BBOX element is defined as a convenient and more compact way of encoding the very common bounding box constraint based on the gml:Envelope geometry. It is equivalent to the spatial operation <fes:Not><fes:Disjoint> … </fes:Disjoint></fes:Not> meaning that the fes:BBOX operator shall identify all geometries that spatially interact with the box.

You probably also need to know about logical operators to combine queries such as and and or.

Finally, there is almost an exact example of exactly what you are trying to do:

<fes:Filter>
  <fes:And>
     <fes:Function name="ClassifiedAs">
        <fes:Literal>RoadTaxonomy</fes:Literal>
        <fes:Literal>Major Highway</fes:Literal>
     </fes:Function>
     <fes:BBOX>
        <fes:ValueReference>/RS1/geometry</fes:ValueReference>
        <gml:Envelope srsName="urn:ogc:def:crs:EPSG::1234http://www.opengis.net/def/crs/epsg/0/1234">
           <gml:lowerCorner>10 10</gml:lowerCorner>
           <gml:upperCorner>20 20</gml:upperCorner>
        </gml:Envelope>
     </fes:BBOX>
  </fes:And>    </fes:Filter>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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