[OpenLayers-Users] doing a search with a buffer

Roald de Wit list at rdewit.net
Sun May 9 21:21:24 EDT 2010


Hi,

 From your other post ('drawing a polygon over selected region'), I 
assume that you're using MapServer. You can quite easily add a spatial 
filter to your WFS request.


            var radius = 100 * 1000; // 100km

            // create point from your lat and lon of your selected feature
            var radiusPoint = new OpenLayers.Geometry.Point(lon, lat);

            var radiusFilter = new OpenLayers.Filter.Spatial({
                 type: OpenLayers.Filter.Spatial.DWITHIN,
                 value: radiusPoint,
                 distanceUnits: "meters",
                 distance: radius
             });

             // assuming this is your vector layer
             layer.filter = radiusFilter;

That should do the trick. Note: if you want to do something similar with 
GeoServer, please note that GS can only use the native distanceUnits for 
that layer. If that layer has degrees as its units, you'd need to 
convert your units from meters to degrees.

Regards, Roald

On 10/05/10 00:17, sunny74 wrote:
> Hi Friends,
>
> I want to do a search with a buffer.
> My scenario is like this.
> I get a structure Id from the user and using that I get the geometry of that
> structure from the postgres DB.
> Now I want to do a search of all structures within a radius of say 100km
> from the structure selected by the user.
> Is there any postgres function which will give the geometry of all features
> lying within a certain radius of a feature..
>
> Has anybody done something like this before?If yes pls share as to how you
> have done it?
>
> Thanks for your attention.
>    




More information about the Users mailing list