[Geoserver-users] WFS query for closest?

Hi all,

I'm trying to use GeoServer WFS to query for the closest feature of a
particular type to a point, but can't seem to get it going. There are
two ways I can think of doing it, but one is far from ideal and the
other isn't supported by the OGC specs:

1) Repeated queries with circular overlaps:
I can simply pick an arbitrary distance, build a circle of that radius
around the query point and use "overlaps" or similar (I know bounding
box would be fastest, but not accurate). If no features are returned,
increase the radius and re-query (rinse, repeat) until features are
returned. This is obviously far from ideal.

2) Return one result and "sort by" distance function:
Unfortunately the OGC specs don't allow for this, but it would be nice
to use "maxFeatures='1'" and then use something similar to -

<ogc:SortBy>
<ogc:SortProperty>
  <ogc:Function name='distance'>...</ogc:Function>
</ogc:SortProperty>
</ogc:SortBy>

Obviously, this doesn't work but does someone else have a
solution/suggestions for where to go next?

Many thanks,

Mark Lidstone
Tel: +44 (0)23 80232222; Fax: +44 (0)23 80232891

BMT Cordah Ltd
Grove House
7 Ocean Way
Ocean Village
Southampton
SO14 3TJ

BMT Cordah Ltd.
A member of the BMT group of companies
Registered Office: Investment House, 6 Union Row, Aberdeen AB10 1DQ
Registered in Scotland No. 163413
http://www.bmtcordah.com/
http://www.bmt.org/

The contents of this e-mail and any attachments are intended only for the use of the e-mail addressee(s) shown. If you are not that person, or one of those persons, you are not allowed to take any action based upon it or to copy it, forward, distribute or disclose the contents of it and you should please delete it from your system. BMT Cordah Limited does not accept liability for any errors or omissions in the context of this e-mail or its attachments, which arise as a result of Internet transmission, nor accept liability for statements which are those of the author and not clearly made on behalf of BMT Cordah Limited.

Hi Mark,

#2 is something I have never considered before and is interesting. You are correct in that it does not work but providing the functionality to sort by a function is an interesting feature. For most datasources its not feasible but for spatial database backends it could work quite well, and not too hard to implement.

However, users have asked for this feature before. Some code has been contributed which performs this functionality, it lives here as a community module:

http://svn.codehaus.org/geoserver/trunk/geoserver/community/

Its not part of the core code base, and more or less untested but it might be a feasible way to proceed.

Other than that, the only other thing would be to wait on WPS, since this sort of thing really falls into that realm. The WPS support also currently lives as a community module on GeoServer 1.7.x but is undergoing active development.

-Justin

Mark Lidstone wrote:

Hi all,

I'm trying to use GeoServer WFS to query for the closest feature of a
particular type to a point, but can't seem to get it going. There are
two ways I can think of doing it, but one is far from ideal and the
other isn't supported by the OGC specs:

1) Repeated queries with circular overlaps:
I can simply pick an arbitrary distance, build a circle of that radius
around the query point and use "overlaps" or similar (I know bounding
box would be fastest, but not accurate). If no features are returned,
increase the radius and re-query (rinse, repeat) until features are
returned. This is obviously far from ideal.

2) Return one result and "sort by" distance function:
Unfortunately the OGC specs don't allow for this, but it would be nice
to use "maxFeatures='1'" and then use something similar to -

<ogc:SortBy>
<ogc:SortProperty>
  <ogc:Function name='distance'>...</ogc:Function>
</ogc:SortProperty>
</ogc:SortBy>

Obviously, this doesn't work but does someone else have a
solution/suggestions for where to go next?

Many thanks,

Mark Lidstone
Tel: +44 (0)23 80232222; Fax: +44 (0)23 80232891
BMT Cordah Ltd Grove House
7 Ocean Way
Ocean Village
Southampton
SO14 3TJ

BMT Cordah Ltd.
A member of the BMT group of companies
Registered Office: Investment House, 6 Union Row, Aberdeen AB10 1DQ
Registered in Scotland No. 163413
http://www.bmtcordah.com/
http://www.bmt.org/

The contents of this e-mail and any attachments are intended only for the use of the e-mail addressee(s) shown. If you are not that person, or one of those persons, you are not allowed to take any action based upon it or to copy it, forward, distribute or disclose the contents of it and you should please delete it from your system. BMT Cordah Limited does not accept liability for any errors or omissions in the context of this e-mail or its attachments, which arise as a result of Internet transmission, nor accept liability for statements which are those of the author and not clearly made on behalf of BMT Cordah Limited.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

--
Justin Deoliveira
The Open Planning Project
jdeolive@anonymised.com