Added by David Robison, last edited by David Robison on Sep 19, 2007  (view change)

Labels

 
(None)

The WFS GetNearest Plug-in is used to get a feature from the WFS that is nearest to a given point. Along with the feature, the distance and bearing is also returned as new feature attributes.

Installing the Plug-in

To install the plug-in, copy the plug-in JAR (ORCI-GetNearestPlugin-1.0-jar) to geoserver's WEB-INF/lib directory. Upon startup, geoserver will automatically detect the plugin and add the GetNearest request to its WFS service.

WFS Request

 The GetNearest request takes a few custom parameters:

Parameter Description
Point The point from which to find the nearest feature.
MaxRange The maximum search range from the point.
Units The units for the search range.

Along with these parameters, custom filters may be added to the request as with the GetFeature WFS request.

Sample Request

http://localhost:8080/geoserver/wfs?request=getNearest&service=wfs&version=1.0.0&typename=tiger:pl&PropertyName=tiger:name,lsad_trans
&POINT=-77.51761,37.02235&MAXRANGE=50&UNITS=mi

This request will return the nearest feature from the tiger:pl layer to the point -77.51761,37.02235. The maximum search range is set to 50 miles. This request will return the following feature set.

<wfs:FeatureCollection
xsi:schemaLocation="http://www.census.gov
http://localhost:8080/geoserver/wfs/DescribeFeatureType?typeName=tiger:pl
http://www.opengis.net/wfs
http://localhost:8080/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd">
  <gml:boundedBy>
    <gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
      <gml:coordinates decimal="." cs="," ts=" ">
        -77.406378,36.940298 -77.391313,36.956486
      </gml:coordinates>
    </gml:Box>
  </gml:boundedBy>
  <gml:featureMember>
    <tiger:pl fid="pl.302">
      <tiger:name>Stony Creek</tiger:name>
      <tiger:lsad_trans>town</tiger:lsad_trans>
      <tiger:nearest_distance>7.760402085851028</tiger:nearest_distance>
      <tiger:nearest_bearing>228.81705674288395</tiger:nearest_bearing>
    </tiger:pl>
  </gml:featureMember>
</wfs:FeatureCollection>

Notice that two new attributes have been added to the feature.

Attribute Description
nearest_distance
This is the distance from the given point to the feature in the units specified in the request.
nearest_bearing This is the compass bearing from the point to the feature in degrees.

Plug-in Details

The following source files make up the plug-in. 

Classes
Description
FeatureBoundsFeatureCollection This class is used to return only the attributes of a feature specified on the request (&Property=).
GetNearest This class extends the WFService class and adds the new GetNearest request to the WFS.
GetNearestHandler This class is the SAX Parser handler used to parse the XML request sent in an HTTP POST request.
GetNearestKvpReader This class reads the Key-Value-Pair parameters included on the request URL.
GetNearestRequest This class holds the GetNearest request parameters.
GetNearestResponse This class is responsible for executing the GetNearest request and identifying the nearest feature.
GetNearestResponseDelegate This is an interface defining a general response delegate.
GetNearestResponseDelegateProducerSpi This is an interface defining a general response delegate factory.
GetNearestResults This class holds the response to the GetNearest request. In the case of this request, it will have a single feature.
GetNearestXmlReader This class is the SAX Parser XML reader used to parse the XML request sent in an HTTP POST request.
GML2GetNearestResponseDelegate This is the response delegate responsible for generating GML2 output.
GML2GetNearestResponseDelegateFactory This is the delegate factory for creating the GML2GetNearestResponseDelegate.

Along with these classes, there are two configuration files.

Configuration file
Description
com.orci.geoserver.wfs.getnearest.GetNearestResponseDelegateProducerSpi This file registers the delegate response factories. This file is saved in the META-INF/services directory of the JAR.
applicationContext.xml This file registers the GetNearest request with the WFS service. This file is saved in the root directory of the JAR.

 Building the Plug-in

This plug-in is built with ant and ivy

Powered by a free Atlassian Confluence Open Source Project License granted to GeoServer . Evaluate Confluence today.

GeoServer wiki is hosted by OpenGeo - Contact Administrators