4

At the moment I have a WFS with the following cql_filter:

'cql_filter: 'dwithin(bag:geometrie, point(lon lat), 100, meters)'

The problem is that this filter does not sort the features from closest to farthest.

I would like to know if anybody is either able to sort this list appropriately, or if anybody knows how to get the closest feature in another way.

1 Answer 1

1

According to Andrea at http://osgeo-org.1560.x6.nabble.com/find-nearest-features-around-point-without-distance-parameter-td3787318.html:

There is no standard WFS filter doing that, but we have a WPS process offering such functionality. It works without requiring special supports from the data access level, as such it's generic and not super fast.

What rather works for me is to use a SQL view (in GeoServer) with viewparams to pass in the coordinates like: &viewparams=lng:12.3;lat:23.4 instead of the cql_filter

and then use PostGIS's <-> operator to order by, selecting the first result ref: https://postgis.net/docs/geometry_distance_knn.html

select * from bag.geometrie
ORDER BY geom <-> 'SRID=4326;POINT(%lng% %lat%)'::geometry 
limit 1 

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.