1

I'm trying to do a WFS GetFeature with Geotools 18.1 but when passing GeometryCollection or MultiLineString as geometry, the GML geometry is empty and I get a 400 Bad Request error.

I Wiresharked what was actually sent in the body, and discovered that the geometry is correctly sent for Point, LineString, Polygon and (weirdly) MultiPoint but not from MultiLineString, MultiPolygon or GeometryCollection

Here is the Java code I use:

Map<String, Serializable> connectionParams = new HashMap<>();
        connectionParams.put("WFSDataStoreFactory:GET_CAPABILITIES_URL", url);

WFSDataStore dataStore = new WFSDataStoreFactory().createDataStore(connectionParams);
SimpleFeatureSource source = dataStore.getFeatureSource(layer.getTypeName());
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
DWithin filter = ff.dwithin(ff.property(layer.getGeomProp()), ff.literal(geometry), distance, "meters");
Query query = new Query(layer.getTypeName(), filter);
SimpleFeatureCollection collection = source.getFeatures(query);

For MultiPoint, this is the GML that is sent with the POST request :

<fes:Filter>
    <fes:DWithin>
        <fes:ValueReference>the_geom</fes:ValueReference>
        <gml:MultiPoint srsDimension="2">
            <gml:pointMember>
                <gml:Point srsDimension="2">
                    <gml:pos>660233.0923782634 6853235.731917043</gml:pos>
                </gml:Point>
            </gml:pointMember>
            <gml:pointMember>
                <gml:Point srsDimension="2">
                    <gml:pos>660233.2971014512 6853265.603009563</gml:pos>
                </gml:Point>
            </gml:pointMember>
            <gml:pointMember>
                <gml:Point srsDimension="2">
                    <gml:pos>660229.5976598886 6853301.00349128</gml:pos>
                </gml:Point>
            </gml:pointMember>
        </gml:MultiPoint>
        <fes:Distance>50.0</fes:Distance>
    </fes:DWithin>
</fes:Filter>

For exactly the same code, but passing a MultiLineString as geometry :

<fes:Filter>
    <fes:DWithin>
        <fes:ValueReference>the_geom</fes:ValueReference>
        <gml:MultiLineString/>
        <fes:Distance>50.0</fes:Distance>
    </fes:DWithin>
</fes:Filter>

Which causes Geoserver to return 400 Bad Request.

Edit :
Small clarification : "splitting" GeometryCollections and send one request for each Geometry does workd (unsurprisingly), but it adds extra unnecessary requests and code to maintain that I'd like to avoid.

Morysh
  • 71
  • 10
  • That looks like a bug, please open a ticket at https://osgeo-org.atlassian.net/projects/GEOT/issues, if possible add the code you are using to generate the issue and some example geometries – Ian Turton Sep 18 '19 at 07:11

0 Answers0