[Geoserver-users] DWITHIN Filter in WFS

Hi All

It may asked before, but i cant get any answer after searching . I just
could not figure out how to use finters in openlayer, please have a look of
the code.

// initailise the map
var options = {
        projection: new OpenLayers.Projection("EPSG:900913"),
        displayProjection: new OpenLayers.Projection("EPSG:4326"),
        units: "m",
        numZoomLevels: 18,
        maxResolution: 156543.0339,
        maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508,
20037508.34)
    };
    
    map = new OpenLayers.Map('mapDiv', options);

function distanceSearch(city){
                nameFilter = new OpenLayers.Filter.Spatial({
                        type: OpenLayers.Filter.Spatial.DWITHIN,
                        value: city.geometry,
// city.geometry returns POINT(52.215263 0.1222)
                        property: 'the_geom',
                        distance:20000,
                        distanceUnits:'m'
                
                });
                
                _xml = new OpenLayers.Format.XML();
                
                var temp = Filter.write(nameFilter);
                var stringFilter = _xml.write(temp);
                
                var url = wfsHost;
                options = {
                        outputformat:'json',
                        extractAttributes:true,
                        Request:'GetFeature',
                        version:'1.1.0',
                        typename:'myproject:stores',
                        filter: stringFilter
                };
                OpenLayers.loadURL(url,options,null,distanceSearchEnd);
                
        }

it will return all the data in stores layer, the filter does not filter
anything out.

Where am i doing wrong??

thanks

--
View this message in context: http://www.nabble.com/DWITHIN-Filter-in-WFS-tp25530632p25530632.html
Sent from the GeoServer - User mailing list archive at Nabble.com.

Hi,

You might have better luck on the openlayers list. That said if you can run with Firebug and get the actual XML request that is being sent to GeoServer we can help further.

-Justin

Jas_gao wrote:

Hi All

It may asked before, but i cant get any answer after searching . I just
could not figure out how to use finters in openlayer, please have a look of
the code.

// initailise the map var options = { projection: new OpenLayers.Projection("EPSG:900913"), displayProjection: new OpenLayers.Projection("EPSG:4326"), units: "m", numZoomLevels: 18, maxResolution: 156543.0339, maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508,
20037508.34) };
        map = new OpenLayers.Map('mapDiv', options);

function distanceSearch(city){ nameFilter = new OpenLayers.Filter.Spatial({ type: OpenLayers.Filter.Spatial.DWITHIN, value: city.geometry, // city.geometry returns POINT(52.215263 0.1222) property: 'the_geom', distance:20000, distanceUnits:'m'
                                });
                                _xml = new OpenLayers.Format.XML();
                                var temp = Filter.write(nameFilter); var stringFilter = _xml.write(temp);
                                var url = wfsHost; options = { outputformat:'json', extractAttributes:true, Request:'GetFeature', version:'1.1.0', typename:'myproject:stores', filter: stringFilter }; OpenLayers.loadURL(url,options,null,distanceSearchEnd);
                        }

it will return all the data in stores layer, the filter does not filter
anything out.

Where am i doing wrong??

thanks

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Your map and data are in degrees and GeoServer pays no attention to
your units parameter in the filter so you are asking for all cities
inside 2000 degrees of the point (i.e. all of them). Either estimate
the distance in degrees (not really correct but will work quickly) or
reproject the layer in to an equal area projection (see
http://www.equal-area-maps.com/index.php)

Ian

On Tue, Sep 22, 2009 at 4:55 AM, Jas_gao <jas_gao@anonymised.com> wrote:

Hi All

It may asked before, but i cant get any answer after searching . I just
could not figure out how to use finters in openlayer, please have a look of
the code.

function distanceSearch(city){
nameFilter = new OpenLayers.Filter.Spatial({
type: OpenLayers.Filter.Spatial.DWITHIN,
value: city.geometry,
// city.geometry returns POINT(52.215263 0.1222)
property: 'the_geom',
distance:20000,
distanceUnits:'m'

           \}\);

--
Ian Turton

Sent from State College, PA, United States