[Geoserver-devel] FindNearest

I have a client who needs to find the nearest street for a list of points (his street map doesn't align with his car layers).

So I'd like to extend the WFS Filter function to provide a FindNearest function. I have an example query below.

Ideally, I'd like to pass the id of the point back with the street name, but that is not a requirement. (I suspect it will make it harder).

--

So far, I've worked out how to write a FindNearest query with minor extensions to JCS.

Jody has recommended I create a Geoserver plugin as per: http://docs.codehaus.org/display/GEOSDEV/3+A+Simple+PlugIn
However, if I do that I assume I don't get access to the filter code?

Questions:
1. Which file(s) should I update? I assume it is something in org.vfny.geoserver.wfs.requests .

2. Should this functionality be rolled back into the Geoserver codebase? It is not part of the WFS Spec, but I suspect that it would be useful for others.

<wfs:GetFeature service="WFS" version="1.0.0"
   outputFormat="GML2"
   xmlns:topp="http://www.openplans.org/topp&quot;
   xmlns:wfs="http://www.opengis.net/wfs&quot;
   xmlns:ogc="http://www.opengis.net/ogc&quot;
   xmlns:gml="http://www.opengis.net/gml&quot;
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
   xsi:schemaLocation="http://www.opengis.net/wfs
                       http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd&quot;&gt;
   <wfs:Query typeName="topp:states">
     <ogc:PropertyName>topp:STATE_NAME</ogc:PropertyName>
     <ogc:Filter>
       <ogc:FindNearest>
         <ogc:PropertyName>the_geom</ogc:PropertyName>
         <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
           <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
         </gml:Point>
       </ogc:FindNearest>

       <ogc:FindNearest>
         <ogc:PropertyName>the_geom</ogc:PropertyName>
         <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
           <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
         </gml:Point>
       </ogc:FindNearest>
    </ogc:Filter>
   </wfs:Query>
</wfs:GetFeature
--
Cameron Shorter
http://cameron.shorter.net

This functionality would be great for a reverse-geocoder and I'm sure people would like to have it in the geoserver codebase. But if it is a plugin with the new framework, then people will be able to just drop it in and go (I think).
I will leave it for the 1.4 people on the list to answer on how to do this exactly.

cheers

Brent Owens
(The Open Planning Project)

Cameron Shorter wrote:

I have a client who needs to find the nearest street for a list of points (his street map doesn't align with his car layers).

So I'd like to extend the WFS Filter function to provide a FindNearest function. I have an example query below.

Ideally, I'd like to pass the id of the point back with the street name, but that is not a requirement. (I suspect it will make it harder).

--

So far, I've worked out how to write a FindNearest query with minor extensions to JCS.

Jody has recommended I create a Geoserver plugin as per: http://docs.codehaus.org/display/GEOSDEV/3+A+Simple+PlugIn
However, if I do that I assume I don't get access to the filter code?

Questions:
1. Which file(s) should I update? I assume it is something in org.vfny.geoserver.wfs.requests .

2. Should this functionality be rolled back into the Geoserver codebase? It is not part of the WFS Spec, but I suspect that it would be useful for others.

<wfs:GetFeature service="WFS" version="1.0.0"
   outputFormat="GML2"
   xmlns:topp="http://www.openplans.org/topp&quot;
   xmlns:wfs="http://www.opengis.net/wfs&quot;
   xmlns:ogc="http://www.opengis.net/ogc&quot;
   xmlns:gml="http://www.opengis.net/gml&quot;
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
   xsi:schemaLocation="http://www.opengis.net/wfs
                       http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd&quot;&gt;
   <wfs:Query typeName="topp:states">
     <ogc:PropertyName>topp:STATE_NAME</ogc:PropertyName>
     <ogc:Filter>
       <ogc:FindNearest>
         <ogc:PropertyName>the_geom</ogc:PropertyName>
         <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
           <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
         </gml:Point>
       </ogc:FindNearest>

       <ogc:FindNearest>
         <ogc:PropertyName>the_geom</ogc:PropertyName>
         <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
           <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
         </gml:Point>
       </ogc:FindNearest>
    </ogc:Filter>
   </wfs:Query>
</wfs:GetFeature
  

I made the assumption that I should be developing on the trunk. Is that right, or should I be using a branch?

Brent Owens wrote:

This functionality would be great for a reverse-geocoder and I'm sure people would like to have it in the geoserver codebase. But if it is a plugin with the new framework, then people will be able to just drop it in and go (I think).
I will leave it for the 1.4 people on the list to answer on how to do this exactly.

cheers

Brent Owens
(The Open Planning Project)

Cameron Shorter wrote:

I have a client who needs to find the nearest street for a list of points (his street map doesn't align with his car layers).

So I'd like to extend the WFS Filter function to provide a FindNearest function. I have an example query below.

Ideally, I'd like to pass the id of the point back with the street name, but that is not a requirement. (I suspect it will make it harder).

--

So far, I've worked out how to write a FindNearest query with minor extensions to JCS.

Jody has recommended I create a Geoserver plugin as per: http://docs.codehaus.org/display/GEOSDEV/3+A+Simple+PlugIn
However, if I do that I assume I don't get access to the filter code?

Questions:
1. Which file(s) should I update? I assume it is something in org.vfny.geoserver.wfs.requests .

2. Should this functionality be rolled back into the Geoserver codebase? It is not part of the WFS Spec, but I suspect that it would be useful for others.

<wfs:GetFeature service="WFS" version="1.0.0"
   outputFormat="GML2"
   xmlns:topp="http://www.openplans.org/topp&quot;
   xmlns:wfs="http://www.opengis.net/wfs&quot;
   xmlns:ogc="http://www.opengis.net/ogc&quot;
   xmlns:gml="http://www.opengis.net/gml&quot;
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
   xsi:schemaLocation="http://www.opengis.net/wfs
                       http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd&quot;&gt;
   <wfs:Query typeName="topp:states">
     <ogc:PropertyName>topp:STATE_NAME</ogc:PropertyName>
     <ogc:Filter>
       <ogc:FindNearest>
         <ogc:PropertyName>the_geom</ogc:PropertyName>
         <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
           <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
         </gml:Point>
       </ogc:FindNearest>

       <ogc:FindNearest>
         <ogc:PropertyName>the_geom</ogc:PropertyName>
         <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
           <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
         </gml:Point>
       </ogc:FindNearest>
    </ogc:Filter>
   </wfs:Query>
</wfs:GetFeature
  
--
Cameron Shorter
http://cameron.shorter.net

depends...
Trunk (1.4) hasn't really been tested by the rest of the developers and hasn't had a release yet, so you might run into a few bumps. The 1.3 branch is stable but you will have to merge your stuff over to 1.4 anyways (that shouldn't be hard though). If you are adding filter stuff you probably just have to play in geotools and not geoserver.

Brent Owens
(The Open Planning Project)

Cameron Shorter wrote:

I made the assumption that I should be developing on the trunk. Is that right, or should I be using a branch?

Brent Owens wrote:

This functionality would be great for a reverse-geocoder and I'm sure people would like to have it in the geoserver codebase. But if it is a plugin with the new framework, then people will be able to just drop it in and go (I think).
I will leave it for the 1.4 people on the list to answer on how to do this exactly.

cheers

Brent Owens
(The Open Planning Project)

Cameron Shorter wrote:

I have a client who needs to find the nearest street for a list of points (his street map doesn't align with his car layers).

So I'd like to extend the WFS Filter function to provide a FindNearest function. I have an example query below.

Ideally, I'd like to pass the id of the point back with the street name, but that is not a requirement. (I suspect it will make it harder).

--

So far, I've worked out how to write a FindNearest query with minor extensions to JCS.

Jody has recommended I create a Geoserver plugin as per: http://docs.codehaus.org/display/GEOSDEV/3+A+Simple+PlugIn
However, if I do that I assume I don't get access to the filter code?

Questions:
1. Which file(s) should I update? I assume it is something in org.vfny.geoserver.wfs.requests .

2. Should this functionality be rolled back into the Geoserver codebase? It is not part of the WFS Spec, but I suspect that it would be useful for others.

<wfs:GetFeature service="WFS" version="1.0.0"
   outputFormat="GML2"
   xmlns:topp="http://www.openplans.org/topp&quot;
   xmlns:wfs="http://www.opengis.net/wfs&quot;
   xmlns:ogc="http://www.opengis.net/ogc&quot;
   xmlns:gml="http://www.opengis.net/gml&quot;
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
   xsi:schemaLocation="http://www.opengis.net/wfs
                       http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd&quot;&gt;
   <wfs:Query typeName="topp:states">
     <ogc:PropertyName>topp:STATE_NAME</ogc:PropertyName>
     <ogc:Filter>
       <ogc:FindNearest>
         <ogc:PropertyName>the_geom</ogc:PropertyName>
         <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
           <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
         </gml:Point>
       </ogc:FindNearest>

       <ogc:FindNearest>
         <ogc:PropertyName>the_geom</ogc:PropertyName>
         <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
           <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
         </gml:Point>
       </ogc:FindNearest>
    </ogc:Filter>
   </wfs:Query>
</wfs:GetFeature
  

In terms of unit tests and cite tests trunk is as well tested as 1.3. However it lacks a release out "in the field". However at the moment we are code complete for 1.4.0, all that remains is documentation.

But as brent stated, the plugging in of filter functions is done at the geotools level so there shouldn't be much you have to play with in geoserver. However as this goes beyond bug fix or minor improvement I would recommened writing it against geoserver trunk as it is going to be the active development branch.

-Justin

Brent Owens wrote:

depends...
Trunk (1.4) hasn't really been tested by the rest of the developers and hasn't had a release yet, so you might run into a few bumps. The 1.3 branch is stable but you will have to merge your stuff over to 1.4 anyways (that shouldn't be hard though). If you are adding filter stuff you probably just have to play in geotools and not geoserver.

Brent Owens
(The Open Planning Project)

Cameron Shorter wrote:

I made the assumption that I should be developing on the trunk. Is that right, or should I be using a branch?

Brent Owens wrote:

This functionality would be great for a reverse-geocoder and I'm sure people would like to have it in the geoserver codebase. But if it is a plugin with the new framework, then people will be able to just drop it in and go (I think).
I will leave it for the 1.4 people on the list to answer on how to do this exactly.

cheers

Brent Owens
(The Open Planning Project)

Cameron Shorter wrote:

I have a client who needs to find the nearest street for a list of points (his street map doesn't align with his car layers).

So I'd like to extend the WFS Filter function to provide a FindNearest function. I have an example query below.

Ideally, I'd like to pass the id of the point back with the street name, but that is not a requirement. (I suspect it will make it harder).

--

So far, I've worked out how to write a FindNearest query with minor extensions to JCS.

Jody has recommended I create a Geoserver plugin as per: http://docs.codehaus.org/display/GEOSDEV/3+A+Simple+PlugIn
However, if I do that I assume I don't get access to the filter code?

Questions:
1. Which file(s) should I update? I assume it is something in org.vfny.geoserver.wfs.requests .

2. Should this functionality be rolled back into the Geoserver codebase? It is not part of the WFS Spec, but I suspect that it would be useful for others.

<wfs:GetFeature service="WFS" version="1.0.0"
  outputFormat="GML2"
  xmlns:topp="http://www.openplans.org/topp&quot;
  xmlns:wfs="http://www.opengis.net/wfs&quot;
  xmlns:ogc="http://www.opengis.net/ogc&quot;
  xmlns:gml="http://www.opengis.net/gml&quot;
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
  xsi:schemaLocation="http://www.opengis.net/wfs
                      http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd&quot;&gt;
  <wfs:Query typeName="topp:states">
    <ogc:PropertyName>topp:STATE_NAME</ogc:PropertyName>
    <ogc:Filter>
      <ogc:FindNearest>
        <ogc:PropertyName>the_geom</ogc:PropertyName>
        <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
          <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
        </gml:Point>
      </ogc:FindNearest>

      <ogc:FindNearest>
        <ogc:PropertyName>the_geom</ogc:PropertyName>
        <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
          <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
        </gml:Point>
      </ogc:FindNearest>
   </ogc:Filter>
  </wfs:Query>
</wfs:GetFeature

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

!DSPAM:1004,44cd4fd16292207481331!

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

Cameron,

As brent said, you should only have to do it at the geotools level in
<Function>. This will almost certainly make your life easier than
trying to hack-up extra elements inside <GetFeature> or <Filter>.

Since you want to take-a-set-of-features-and-reduce-it-to-one-feature
(the nearest one), you should look at what jody's done recently . He
added better support for this (or at least he gave you some examples
to follow).

I'm guessing its going to probably be more complex that whats already
done, but it shouldnt be that difficult.

If you plug-in at this level, it should be quite easy for you to
maintain as you just have to add the jar and any geotools app should
just pick it up. You would access the functionality in the <Filter>
element, something like this:

...
    <Function name='isNearestTo'> <!- or whatever ->
       ... geometry column ...
       ... geometry you're testing against ...
    </Function>
...

NOTE: Make sure you read the Filter spec because there's restrictions
on where you're allowed to put <Function> calls in. Sometimes you
have to 'trick' it so it does what you want. For example, you can
have your function return the FID of the nearest feature and wrap the
<function> in a <FID> filter. Take a look at exactly what you want to
do and see how you can get it to work in the confines of the Filter
spec.
NOTE: Make sure your function doesnt sneakily turn into O(N*N). See
the examples of how to cache results/make sub-queries.

Hopefully jody can fill you in what RR changed as what they did is
supposed to make this type of thing easy ...

dave

On 7/30/06, Cameron Shorter <cameron.shorter@anonymised.com> wrote:

I have a client who needs to find the nearest street for a list of
points (his street map doesn't align with his car layers).

So I'd like to extend the WFS Filter function to provide a FindNearest
function. I have an example query below.

Ideally, I'd like to pass the id of the point back with the street name,
but that is not a requirement. (I suspect it will make it harder).

--

So far, I've worked out how to write a FindNearest query with minor
extensions to JCS.

Jody has recommended I create a Geoserver plugin as per:
http://docs.codehaus.org/display/GEOSDEV/3+A+Simple+PlugIn
However, if I do that I assume I don't get access to the filter code?

Questions:
1. Which file(s) should I update? I assume it is something in
org.vfny.geoserver.wfs.requests .

2. Should this functionality be rolled back into the Geoserver codebase?
It is not part of the WFS Spec, but I suspect that it would be useful
for others.

<wfs:GetFeature service="WFS" version="1.0.0"
   outputFormat="GML2"
   xmlns:topp="http://www.openplans.org/topp&quot;
   xmlns:wfs="http://www.opengis.net/wfs&quot;
   xmlns:ogc="http://www.opengis.net/ogc&quot;
   xmlns:gml="http://www.opengis.net/gml&quot;
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
   xsi:schemaLocation="http://www.opengis.net/wfs
                       http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd&quot;&gt;
   <wfs:Query typeName="topp:states">
     <ogc:PropertyName>topp:STATE_NAME</ogc:PropertyName>
     <ogc:Filter>
       <ogc:FindNearest>
         <ogc:PropertyName>the_geom</ogc:PropertyName>
         <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
           <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
         </gml:Point>
       </ogc:FindNearest>

       <ogc:FindNearest>
         <ogc:PropertyName>the_geom</ogc:PropertyName>
         <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
           <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
         </gml:Point>
       </ogc:FindNearest>
    </ogc:Filter>
   </wfs:Query>
</wfs:GetFeature
--
Cameron Shorter
http://cameron.shorter.net

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

David Blasby wrote:

Cameron,

As brent said, you should only have to do it at the geotools level in
<Function>. This will almost certainly make your life easier than
trying to hack-up extra elements inside <GetFeature> or <Filter>.

Since you want to take-a-set-of-features-and-reduce-it-to-one-feature
(the nearest one), you should look at what jody's done recently . He
added better support for this (or at least he gave you some examples
to follow).

Not sure it will help as WFS is only set up to return a selection of contents from an already existing
FeatureCollection. What Cameron is looking for is the ability to return a different content type (Points)
based on the contents of a known feature collection (Lines) ... so we are into web processing
service territory, or simply a custom GeoServer module.

Good times.

Cheers,
Jody

Jody Garnett wrote:

David Blasby wrote:

Cameron,

As brent said, you should only have to do it at the geotools level in
<Function>. This will almost certainly make your life easier than
trying to hack-up extra elements inside <GetFeature> or <Filter>.

Since you want to take-a-set-of-features-and-reduce-it-to-one-feature
(the nearest one), you should look at what jody's done recently . He
added better support for this (or at least he gave you some examples
to follow).

Not sure it will help as WFS is only set up to return a selection of contents from an already existing
FeatureCollection. What Cameron is looking for is the ability to return a different content type (Points)
based on the contents of a known feature collection (Lines) ... so we are into web processing
service territory, or simply a custom GeoServer module.

Good times.

Cheers,
Jody

Jody, I think my findNearest requirement is easier than you suspect.

In the simplest case,
I want to query a road layer. I want to pass in a point, and see which road layer is the closest. Ie. I want to return the road layer feature. (or at least the street name attribute of the road layer).

It is slightly more complicated because I want to pass in multiple points and return multiple street names. But I only want to query one layer.

--
Cameron Shorter
http://cameron.shorter.net

Hi again:

Jody, I think my findNearest requirement is easier than you suspect.

Sweet!

In the simplest case,
I want to query a road layer. I want to pass in a point, and see which road layer is the closest. Ie. I want to return the road layer feature. (or at least the street name attribute of the road layer).
It is slightly more complicated because I want to pass in multiple points and return multiple street names. But I only want to query one layer.

Oh okay - that does sound much much easier.
Dave's answer makes a lot more sense now.
Jody