[mapserver-users] spatial filter DWITHIN unsucessful

Neelima Emmani neelima.emmani at iictechnologies.com
Tue Mar 6 03:19:40 EST 2012


Hi All,

I am working with openlayers, mapserver and post gis. I am facing problem with spatial filter DWITHIN and not able to discover if it is problem with mapserver or not.

Details::::

Now,
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;
    }
    });

    }


MAPFILE ----

MAP
  NAME "QGIS-MAP"
  # Map image size
  SIZE 600 600
  UNITS meters

  EXTENT -101.455432 18.242354 -73.740758 33.963395
  FONTSET './etc/fonts.txt'
  SYMBOLSET './etc/symbols.txt'
  PROJECTION
    'proj=longlat'
    'ellps=WGS84'
    'towgs84=0,0,0,0,0,0,0'
    'no_defs'
  END

  # Background color for the map canvas -- change as desired
  IMAGECOLOR 255 255 255
  IMAGEQUALITY 95
  IMAGETYPE agg

  OUTPUTFORMAT
    NAME agg
    DRIVER AGG/PNG
    IMAGEMODE RGB
  END
  # Legend
  LEGEND
      IMAGECOLOR 255 255 255
    STATUS ON
    KEYSIZE 18 12
    LABEL
      TYPE BITMAP
      SIZE MEDIUM
      COLOR 0 0 89
    END
  END

  # Web interface definition. Only the template parameter
  # is required to display a map. See MapServer documentation
  WEB
    # Set IMAGEPATH to the path where MapServer should
    # write its output.
    IMAGEPATH '/ms4w/tmp/ms_tmp/'

    # Set IMAGEURL to the url that points to IMAGEPATH
    # as defined in your web server configuration
    IMAGEURL '/ms_tmp/'

    # WMS server settings
    METADATA
      'ows_title'           'QGIS-MAP'
      'ows_onlineresource'  'http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/Apache/htdocs/qgismapserv_org/xyz.map&'
      'ows_srs'             'EPSG:4326 EPSG:900913'
      'ows_enable_request'  'GetMap GetFeature GetFeatureInfo *'   ##necessary
    END

    #Scale range at which web interface will operate
    # Template and header/footer settings
    # Only the template parameter is required to display a map. See MapServer documentation
    #TEMPLATE 'fooOnlyForWMSGetFeatureInfo'
  END

  LAYER
    NAME 'xyz'
    TYPE POINT
    DUMP true
    #TEMPLATE fooOnlyForWMSGetFeatureInfo
    EXTENT -101.455432 18.242354 -73.740758 33.963395
    CONNECTIONTYPE postgis
    CONNECTION "dbname='postgis' host=localhost port=5432 user='postgres' password='xxx' sslmode=disable"
    DATA 'the_geom FROM us1gc09m USING UNIQUE fids'
    METADATA
      'ows_title' 'xyz'
      'wfs_typename' 'xyz'
      'wfs_version' '1.0.0'
      'wfs_connectiontimeout' '60'
      'wfs_maxfeatures' '150'
      'wfs_filter' 'GET'
      'wfs_featureid' 'the_geom'
    END
    STATUS OFF
    TRANSPARENCY 100
    PROJECTION
    'proj=longlat'
    'ellps=WGS84'
    'towgs84=0,0,0,0,0,0,0'
    'no_defs'
    END
    CLASS
       NAME 'xyz'
       STYLE
         SYMBOL "circle"
         SIZE 7.0
         OUTLINECOLOR 0 0 0
         COLOR 123 143 78
       END
    END
  END

END

Awaiting for a solution.

With Regards,
Neelima Emmani
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20120306/4e1cddaf/attachment-0001.html


More information about the mapserver-users mailing list