[OpenLayers-Users] Spatial Filter DWITHIN unsuccessful

Neelima Emmani neelima.emmani at iictechnologies.com
Tue Mar 6 01:00:50 EST 2012


Hi All,

I am working with openlayers , mapserver, postgis.

I have google map as a base map and overlayed few point layers. Now, i want to do filtering with respect to the path that's drew on the map. For this path , i am using  draw feature with OpenLayers.Handler.Path. Upto here it is working fine. I can draw a line. Now using the line geometry ,  i am giving a spatial filter DWITHIN with a distance of  2000 and also mentioned distanceUnits as  'm'. After i draw a line , the spatial filter for DWITHIN gets activated and the layer to be filtered is completely disappearing. Now what i found is, it is throwing a WFS exception as below -

msWFSGetFeature(): WFS server error. Invalid or Unsupported FILTER in GetFeature :
(<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:And><ogc:DWithin><ogc:PropertyName>the_geom</ogc:PropertyName><gml:MultiLineString xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:900913"><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">-79.205932617188,32.309033345029 -79.458618164063,32.267239420261 -79.851379394531,32.144067753448 -78.255615234375,33.130344611623</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString><ogc:Distance units="m">200000</ogc:Distance></ogc:DWithin><ogc:BBOX><ogc:PropertyName>the_geom</ogc:PropertyName><gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"><gml:coordinates decimal="." cs="," ts=" ">-84.100341796875,29.910254

 244941 -73.114013671875,34.556260876457</gml:coordinates></gml:Box></ogc:BBOX></ogc:And></ogc:Filter>

And then I checked with get Capabilities , It is spatial filter DWITHIN capable. After that I checked by copying my WFS layer url along with filter properties as below -

http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/openlayers-2.10/examples/us1gc09m-addline.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=us1gc09m&Filter=%3CFilter%3E%3CDWithin%3E%3CPropertyName%3Ethe_geom%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E-80.22217%2031.07991%3C/gml:coordinates%3E%3C/gml:Point%3E%3CDistance%20units=%27m%27%3E100%3C/Distance%3E%3C/DWithin%3E%3C/Filter%3E

into a browser. With this, It works well. No exception is thrown and the query is done properly. So, now, i do not understand where is the problem lies.

Can any one tell me how to solve this. How to do Spatial filter DWITHIN.  And is my approach right?
Below is my JS code ---

var map;
var spatialfilter;

    function init() {
     map = new OpenLayers.Map("map");

//GOOGLE MAP
    var base = new OpenLayers.Layer.Google("Google Hybrid", {'type': G_HYBRID_MAP});
        map.addLayer(base);
//CREATE WMS LAYER
    var wms = new OpenLayers.Layer.WMS("wms", "http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/openlayers-2.10/examples/xyz.map",
                  {layers: 'xyz'}, {isBaseLayer: false, visibility: false, opacity: 0.5, singleTile: true});
        map.addLayer(wms);

//VECTOR LAYER FOR PANEL
    var vlayer = new OpenLayers.Layer.Vector("vlayer");
    map.addLayer(vlayer);


// CREATE WFSLAYERS

//style map for points
    var styleMap = new OpenLayers.StyleMap(OpenLayers.Util.applyDefaults({fillColor: "CYAN", fillOpacity: 1, strokeColor: "black"},
        OpenLayers.Feature.Vector.style["default"]));

// mock up a protocol for synchronous and successful commits
    var wfs_protocol = new OpenLayers.Protocol.WFS({url:"http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/openlayers-2.10/examples/xyz.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=xyz",
                                featureType: "xyz",
                                srsName: "EPSG:900913"});

    var wfslayer = new OpenLayers.Layer.Vector("WFS", {styleMap: styleMap,
                                                        strategies: [new OpenLayers.Strategy.BBOX()],
                                                        protocol: wfs_protocol
                                                });

    map.addLayer(wfslayer);

    map.addControl(new OpenLayers.Control.MousePosition());
    map.addControl(new OpenLayers.Control.LayerSwitcher());
 //MAP CONTROLS
    var defStyle = {strokeColor: "red", strokeOpacity: "0.7", strokeWidth: 1, fillColor: "red", pointRadius: 3, cursor: "pointer"};
    var sty = OpenLayers.Util.applyDefaults(defStyle, OpenLayers.Feature.Vector.style["default"]);


    var DeleteFeature = OpenLayers.Class(OpenLayers.Control, {
    initialize: function(layer, options) {
        OpenLayers.Control.prototype.initialize.apply(this, [options]);
        this.layer = layer;
        this.handler = new OpenLayers.Handler.Feature(
            this, layer, {click: this.clickFeature}
        );
    },
    clickFeature: function(feature) {
        // if feature doesn't have a fid, destroy it
        if(feature.fid == undefined) {
            this.layer.destroyFeatures([feature]);
        } else {
            feature.state = OpenLayers.State.DELETE;
            this.layer.events.triggerEvent("afterfeaturemodified", {feature: feature});
            feature.renderIntent = "select";
            this.layer.drawFeature(feature);
        }
    },
    setMap: function(map) {
        this.handler.setMap(map);
        OpenLayers.Control.prototype.setMap.apply(this, arguments);
    },
    CLASS_NAME: "OpenLayers.Control.DeleteFeature"
});



    var panel = new OpenLayers.Control.Panel(
        {'displayClass': 'customEditingToolbar'}
    );

        var navigate = new OpenLayers.Control.Navigation({
        title: "Pan Map"
        });

        var drawpath = new OpenLayers.Control.DrawFeature(
        vlayer, OpenLayers.Handler.Path,
        {
            title: "Draw Path",
            displayClass: "olControlDrawFeaturePath",
            multi: true
        }
        );

        var drawpoint = new OpenLayers.Control.DrawFeature(
        vlayer, OpenLayers.Handler.Point,
        {
            title: "Add Point",
            displayClass: "olControlDrawFeaturePoint",
            multi: true
        }
        );

        var box = new OpenLayers.Control.DrawFeature(vlayer,
                        OpenLayers.Handler.RegularPolygon, {
                            handlerOptions: {
                                sides: 4,
                                irregular: true
                            } ,
                            title: "Box Feature Select",
                            displayClass: "olControlDrawFeatureBox"});

        var edit = new OpenLayers.Control.ModifyFeature(vlayer, {
        title: "Modify Feature",
        displayClass: "olControlModifyFeature"
        });

        var del = new DeleteFeature(vlayer, {title: "Delete Feature"});

    panel.addControls([navigate,del, edit, box, drawpoint, drawpath]);

    panel.defaultControl = navigate;
    map.addControl(panel);
    panel.activate();
    map.zoomToMaxExtent();
    map.setCenter(new OpenLayers.LonLat(-82, 28),5);

    vlayer.events.on({
    beforefeatureadded: function(event) {                //here also tried with featureadded
        var geometry = event.feature.geometry;
        alert(geometry);
        wfslayer.filter = new OpenLayers.Filter.Spatial({
            type: OpenLayers.Filter.Spatial.DWITHIN,
            property: "the_geom",
            value: event.feature.geometry,
            distance: 200000,
            distanceUnits: 'm'
        });
        wfslayer.refresh({force: true});
        var style_green =
     {
         strokeColor: "#00FF00",
         strokeOpacity: 0.7,
         strokeWidth: 4,
         graphicName: 'square',
         fillColor: '#FF0000',
         pointRadius: 5
     };
        vlayer.drawFeature(event.feature, style_green);
        alert(wfslayer.filter.evaluate(event.feature));
        return false;
    }
    });

    }
With Regards,
Neelima Emmani
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120306/1ba05fe2/attachment-0001.html


More information about the Users mailing list