<html><head></head><body><div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px">Hi Jukka Rahkonen,<div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" id="yui_3_16_0_ym19_1_1493992961293_13603" style="display: block;"><div style="font-family: Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 13px;" id="yui_3_16_0_ym19_1_1493992961293_13602"><div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif; font-size: 16px;" id="yui_3_16_0_ym19_1_1493992961293_13601"><div class="y_msg_container" id="yui_3_16_0_ym19_1_1493992961293_13618"><div id="yiv6196364185"><div id="yui_3_16_0_ym19_1_1493992961293_13620"><div style="color:#000;background-color:#fff;font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px;" id="yui_3_16_0_ym19_1_1493992961293_13619"><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4535"><br clear="none"></div><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4534">Thanks a lot for your help and doing this exercise. I really appreciate it, it's really nice group to get/share inputs on any issue on MapServer.<br clear="none"></div><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4533"><span><br clear="none"></span></div><div dir="ltr" id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4643"><span id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4707">Well I've found the solution now. I was missing <span style="background-color:rgb(143, 202, 64);"><font id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_6340"><b id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_6339">EXTENT </b></font></span>parameter in map file. After adding it according to source data, it started working. Thanks a lot Jukka.</span></div><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4532"><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4778"><br clear="none"></div><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4756">Just want to mention a point here, it still has a default spatial filter in PostGIS query, but this time with correct coordinates according to EXTENT defined in map file. <br clear="none"></div><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_6148"><br clear="none"></div><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_6147">Thanks again to all. Have a nice weekend!<br clear="none"></div><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_6124"><br clear="none"></div><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_6125">Cheers!<br clear="none"></div><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4755"><br clear="none"></div></div><div class="yiv6196364185signature" id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4531"><font id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4708" size="2">Regards,<br clear="none">Kajod<br clear="none"></font></div><div class="yiv6196364185qtdSeparateBR" id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4530"><br clear="none"><br clear="none"></div><div class="yiv6196364185yqt1119684511" id="yiv6196364185yqt94293"><div class="yiv6196364185yahoo_quoted" id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4444" style="display:block;">  <div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4443" style="font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px;"> <div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4442" style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif;font-size:16px;"> <div dir="ltr" id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4441"> <font id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4527" face="Arial" size="2"> </font><hr id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4529" size="1"> <b><span style="font-weight:bold;">From:</span></b> Rahkonen Jukka (MML) <jukka.rahkonen@maanmittauslaitos.fi><br clear="none"> <b><span style="font-weight:bold;">To:</span></b> Jeff McKenna <jmckenna@gatewaygeomatics.com>; "mapserver-users@lists.osgeo.org" <mapserver-users@lists.osgeo.org>; Kajod Sharma <kajod4u@yahoo.com> <br clear="none"> <b><span style="font-weight:bold;">Sent:</span></b> Thursday, 4 May 2017 8:02 PM<br clear="none"> <b><span style="font-weight:bold;">Subject:</span></b> Re: [mapserver-users] Issue in using MapServer WFS Filter<br clear="none">  </div> <div class="yiv6196364185y_msg_container" id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4449"><br clear="none"><div id="yiv6196364185"><style type="text/css">#yiv6196364185   --P{margin-top:0;margin-bottom:0;}#yiv6196364185 </style><div dir="ltr" id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4469">
<div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4468">Hi,</div>
<div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4471"><br clear="none">
</div>
<div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4473">I saved the states.shp file from the demo data directory that installs with GeoServer into PostGIS.</div>
<div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4475"><br clear="none">
</div>
<div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4476">This query finds Kansas:<br clear="none">
</div>
<div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4827"><br clear="none">
</div>
<div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4478"><a rel="nofollow" shape="rect" id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4477" target="_blank" onclick="return window.theMainWindow.showLinkWarning(this)" href="http://localhost:8060/cgi-bin/mapserv.exe?service=WFS&map=c:\ms4w_data\apps\states_pg.map&request=GetFeature&version=2.0.0&typeNames=ms:states_pg&FILTER=%3CFilter%3E%3CContains%3E%3CPropertyName%3EmsGeometry%3C/PropertyName%3E%3Cgml:Point%20srsName=%22urn:ogc:def:crs:EPSG::4326%22%3E%3Cgml:coordinates%3E40,-100%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Contains%3E%3C/Filter%3E">http://localhost:8060/cgi-bin/mapserv.exe?service=WFS&map=c:\ms4w_data\apps\states_pg.map&request=GetFeature&version=2.0.0&typeNames=ms:states_pg&FILTER=%3CFilter%3E%3CContains%3E%3CPropertyName%3EmsGeometry%3C/PropertyName%3E%3Cgml:Point%20srsName=%22urn:ogc:def:crs:EPSG::4326%22%3E%3Cgml:coordinates%3E40,-100%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Contains%3E%3C/Filter%3E</a></div>
<div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4828"><br clear="none">
</div>
<div>The SQL does contain the && comparison but is is not harmful.</div>
<div><br clear="none">
</div>
<div>My mapfile:</div>
<div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4479"><br clear="none">
</div>
<div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4480">MAP<br clear="none">
NAME "testname"<br clear="none">
SIZE 800 800<br clear="none">
EXTENT -180 -90 180 90<br clear="none">
UNITS DD<br clear="none">
IMAGECOLOR 20 250 250<br clear="none">
SHAPEPATH "c:\ms4w\tmp"<br clear="none">
IMAGETYPE "png"<br clear="none">
OUTPUTFORMAT<br clear="none">
  NAME "geojson"<br clear="none">
  DRIVER "OGR/GEOJSON"<br clear="none">
  MIMETYPE "application/json; subtype=geojson"<br clear="none">
  FORMATOPTION "STORAGE=stream"<br clear="none">
  FORMATOPTION "FORM=SIMPLE"<br clear="none">
END<br clear="none">
WEB<br clear="none">
    METADATA<br clear="none">
        "ows_enable_request" "*"<br clear="none">
        "wms_bbox_extended" "true"<br clear="none">
        "wfs_return_srs_as_urn" "true"<br clear="none">
        "ows_srs" "CRS:84 EPSG:4326 EPSG:32634 EPSG:3857 EPSG:2923"<br clear="none">
        "wms_title" "MS 6.1.1 WMS from Spatialite"<br clear="none">
        "wfs_title" "MS 6.1.1 WFS from Spatialite"<br clear="none">
        "wfs_abstract" "ööää"<br clear="none">
        "wfs_onlineresource" "http://localhost:8060/cgi-bin/mapserv.exe?map=c:\ms4w\apps\wms-wfs.map"<br clear="none">
       # "wfs_use_default_extent_for_getfeature" "no"<br clear="none">
     END<br clear="none">
END<br clear="none">
DEBUG 10<br clear="none">
CONFIG "PROJ_LIB" "C:/ms4w/proj/nad"<br clear="none">
CONFIG "CPL_DEBUG" "ON"<br clear="none">
CONFIG "SQLITE_LIST_ALL_TABLES" "TRUE"<br clear="none">
CONFIG "MS_ERRORFILE" "c:/ms4w/tmp/debug.txt"<br clear="none">
PROJECTION<br clear="none">
"init=epsg:4326"<br clear="none">
END<br clear="none">
LAYER<br clear="none">
NAME "states_pg"<br clear="none">
STATUS DEFAULT<br clear="none">
CONNECTIONTYPE POSTGIS<br clear="none">
CONNECTION "dbname=xxx user=yyy"<br clear="none">
DATA "geom from states using unique gid using srid=4326"<br clear="none">
PROCESSING "CLOSE_CONNECTION=DEFER"<br clear="none">
TYPE POLYGON<br clear="none">
    STATUS ON<br clear="none">
    PROJECTION<br clear="none">
        "init=epsg:4326"<br clear="none">
    END<br clear="none">
            OPACITY 50<br clear="none">
 METADATA<br clear="none">
      "ows_title"         "states_pg" ##REQUIRED<br clear="none">
      "wfs_srs"           "EPSG:4326" ## REQUIRED<br clear="none">
      "gml_include_items" "all" ## Optional (serves all attributes for layer)<br clear="none">
     # "gml_exclude_items" "STATE_NAME"<br clear="none">
      "gml_featureid"     "gid" ## REQUIRED<br clear="none">
      "gml_types" "auto"<br clear="none">
      "wfs_getfeature_formatlist" "geojson"<br clear="none">
 END<br clear="none">
    CLASS<br clear="none">
        STYLE<br clear="none">
            COLOR 100 200 100<br clear="none">
            OUTLINECOLOR 0 0 0<br clear="none">
        END<br clear="none">
 LABEL<br clear="none">
    COLOR  150 150 150<br clear="none">
    OUTLINECOLOR 255 255 255<br clear="none">
    TYPE bitmap<br clear="none">
    SIZE small<br clear="none">
    POSITION UL<br clear="none">
    #TEXT "[STATE_FIPS]"<br clear="none">
    PARTIALS FALSE<br clear="none">
    END    <br clear="none">
  LABEL<br clear="none">
    COLOR  150 150 150<br clear="none">
    OUTLINECOLOR 255 255 255<br clear="none">
    TYPE bitmap<br clear="none">
    SIZE small<br clear="none">
    POSITION LL<br clear="none">
    #TEXT "[STATE_NAME]"<br clear="none">
    PARTIALS FALSE<br clear="none">
    END      <br clear="none">
    END<br clear="none">
END<br clear="none">
<br clear="none">
END<br clear="none">
</div>
<div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4525"><br clear="none">
</div>
<div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4492">-Jukka Rahkonen-<br clear="none">
</div>
<div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4491"><br clear="none">
</div>
<div class="yiv6196364185yqt0558679285" id="yiv6196364185yqt14472"><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4485" style="color:rgb(33, 33, 33);">
<hr id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4490" tabindex="-1" style="display:inline-block;width:98%;"><br clear="none"><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4484"><div id="yiv6196364185yui_3_16_0_ym19_1_1493992961293_4483" style="color:#000;background-color:#fff;font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px;"><div class="yiv6196364185yahoo_quoted" id="yiv6196364185yui_3_16_0_ym19_1_1493888588951_7112" style="display:block;"><div id="yiv6196364185yui_3_16_0_ym19_1_1493888588951_7111" style="font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px;"><div id="yiv6196364185yui_3_16_0_ym19_1_1493888588951_7110" style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif;font-size:16px;"><div class="yiv6196364185y_msg_container" id="yiv6196364185yui_3_16_0_ym19_1_1493888588951_7190"><div id="yiv6196364185"><div id="yiv6196364185yui_3_16_0_ym19_1_1493888588951_7193"><div id="yiv6196364185yui_3_16_0_ym19_1_1493888588951_7192" style="color:#000;background-color:#fff;font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px;"><div class="yiv6196364185yqt9489998549" id="yiv6196364185yqt15536"><div class="yiv6196364185yahoo_quoted" id="yiv6196364185yui_3_16_0_ym19_1_1493287513971_3172" style="display:block;"><div id="yiv6196364185yui_3_16_0_ym19_1_1493287513971_3171" style="font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px;"><div id="yiv6196364185yui_3_16_0_ym19_1_1493287513971_3170" style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif;font-size:16px;"><div class="yiv6196364185y_msg_container" id="yiv6196364185yui_3_16_0_ym19_1_1493287513971_3169"><div dir="ltr" id="yiv6196364185yui_3_16_0_ym19_1_1493287513971_3168"><div id="yui_3_16_0_ym19_1_1493992961293_13756"><<<<< trimmed message >>>>></div><div id="yui_3_16_0_ym19_1_1493992961293_13757"><br></div>
On 2017-04-26 10:42 AM, Kajod Sharma wrote:<br clear="none">
> Hi,<br clear="none">
><br clear="none">
> Greetings!<br clear="none">
><br clear="none">
> I hope this is a right platform to discuss my query regarding FILTER<br clear="none">
> applied on MapServer WFS.<br clear="none">
><br clear="none">
> I'm new in this area and exploring some features of MapServer. I want to<br clear="none">
> use GetFeature request of WFS to get features applied on any location on<br clear="none">
> map. I'm using "MapServer version 7.0.4 (MS4W 3.2.1)" and trying to<br clear="none">
> apply filter "Contains" for it.<br clear="none">
><br clear="none">
> I can see two problems when it applies Filter query on PostGIS:<br clear="none">
><br clear="none">
> 1. It looks it adds an extra default geospatial filter in it while<br clear="none">
> making a query to PostGIS. This default spatial filter is not stopping<br clear="none">
> to return any result from PostGIS. Is there any way to exclude this<br clear="none">
> default filter?<br clear="none">
> 2. It seems Contains coordinates are not transformed properly according<br clear="none">
> to SRS of data in PostGIS.<br clear="none">
><br clear="none">
> I've tries with different projection in map file and request message<br clear="none">
> with no success.<br clear="none">
><br clear="none">
> Supporting data to give your input on my queries:<br clear="none">
><br clear="none">
> WFS request<br clear="none">
> *************************<br clear="none">
> Formatted Version:<br clear="none">
><br clear="none">
> http://localhost/cgi-bin/mapserv.exe?<br clear="none">
> service=WFS&<br clear="none">
> map=C:/Data/MapServerWFSSample.map&<br clear="none">
> request=GetFeature&<br clear="none">
> version=2.0.0&<br clear="none">
> typeName=SampleLayer&<br clear="none">
> FILTER=<Filter xmlns="<a rel="nofollow" shape="rect" target="_blank" href="http://www.opengis.net/ogc">http://www.opengis.net/ogc</a>"<br clear="none">
> xmlns:gml="<a rel="nofollow" shape="rect" target="_blank" href="http://www.opengis.net/gml">http://www.opengis.net/gml</a>"<br clear="none">
> xmlns:ms="<a rel="nofollow" shape="rect" target="_blank" href="http://mapserver.gis.umn.edu/mapserver">http://mapserver.gis.umn.edu/mapserver</a>"><br clear="none">
>  <*Contains*><br clear="none">
>    <PropertyName>wkb_Geometry</PropertyName><br clear="none">
>    <gml:Point srsName="urn:ogc:def:crs:EPSG::4326"><br clear="none">
>      <gml:coordinates>0.112034,53.567972</gml:coordinates><br clear="none">
>    </gml:Point><br clear="none">
>  </*Contains*><br clear="none">
> </Filter><br clear="none">
> *************************<br clear="none">
><br clear="none">
> PostGIS query [Could see in log file]:<br clear="none">
> *************************<br clear="none">
> msPostGISLayerWhichShapes query: select<br clear="none">
> "Attribute1","Attribute2","Attribute3",encode(ST_AsBinary(ST_Force2D("wkb_geometry"),'NDR'),'hex')<br clear="none">
> as geom from SampleGeoDataTable where */wkb_geometry &&<br clear="none">
> ST_GeomFromText('POLYGON((-0.999462804873474<br clear="none">
> -1.00102606014116,-0.999462804873474<br clear="none">
> -1.00102606014116,-0.999462804873474<br clear="none">
> -1.00102606014116,-0.999462804873474<br clear="none">
> -1.00102606014116,-0.999462804873474<br clear="none">
> -1.00102606014116))',find_srid('','SampleGeoDataTable','wkb_geometry'))/* and<br clear="none">
> (st_contains(wkb_geometry,ST_GeomFromText('POINT<br clear="none">
> (*/7853690.3631838141000000 -5506204.5232773330000000/*)')) = TRUE)<br clear="none">
> *************************<br clear="none">
><br clear="none">
> Similar WFS query to GeoServer works perfectly.<br clear="none">
><br clear="none">
> It would be very helpful if someone can help me on it. Thanks a lot in<br clear="none">
> advance.<br clear="none">
><br clear="none">
> Map File looks like:<br clear="none">
><br clear="none">
> **************************************************<br clear="none">
> MAP<br clear="none">
>  NAME "Sample_WMS"<br clear="none">
>  CONFIG "PROJ_LIB" "C:\ms4w\proj\nad"<br clear="none">
>  CONFIG "MS_ERRORFILE" "C:/Data/ms_tmp/ms_error.txt"<br clear="none">
>  CONFIG "CPL_DEBUG" "ON"<br clear="none">
>  CONFIG "PROJ_DEBUG" "ON"<br clear="none">
>  STATUS ON<br clear="none">
>  PROJECTION<br clear="none">
>    "init=epsg:27700"<br clear="none">
>  END<br clear="none">
><br clear="none">
>  WEB<br clear="none">
>    IMAGEPATH "C:/Data/ms_tmp/"<br clear="none">
>    IMAGEURL "/ms_tmp/"<br clear="none">
>    METADATA<br clear="none">
>    "wfs_enable_request" "*"<br clear="none">
>    "wfs_title"        "My Global Map WFS Server"<br clear="none">
>    "wfs_srs"          "EPSG:4326 EPSG:900913 EPSG:27700"<br clear="none">
>    "wfs_boundingbox"    "EPSG:27700 749.099975585938 -90036.5<br clear="none">
> 660460.875 1227306.5"<br clear="none">
>    END<br clear="none">
>  END<br clear="none">
><br clear="none">
>  LAYER<br clear="none">
>    NAME "SampleLayer"<br clear="none">
>    STATUS DEFAULT<br clear="none">
>    TYPE POLYGON<br clear="none">
>    PROJECTION<br clear="none">
>    "init=epsg:27700"<br clear="none">
>    END<br clear="none">
>    CONNECTIONTYPE POSTGIS<br clear="none">
>    CONNECTION "host=localhost port=5432 dbname=SampleGeoDataTable<br clear="none">
> user=postgres password=hahaha"<br clear="none">
>    DATA "wkb_geometry from SampleLayer"<br clear="none">
>    CLASS<br clear="none">
>      STYLE<br clear="none">
>      COLOR      0 100 255<br clear="none">
>      OUTLINECOLOR 0 0 0<br clear="none">
>      END<br clear="none">
>    END<br clear="none">
><br clear="none">
>    METADATA<br clear="none">
>    "wfs_enable_request" "*"<br clear="none">
>    "wfs_title"        "Sample WFS"<br clear="none">
>    "wfs_srs"          "EPSG:27700 EPSG:4326 EPSG:900913"<br clear="none">
>    "wfs_boundingbox"    "EPSG:27700 749.099975585938 -90036.5<br clear="none">
> 660460.875 1227306.5"<br clear="none">
>    "gml_include_items" "all"<br clear="none">
>    END<br clear="none">
>  END<br clear="none">
> END<br clear="none">
> **************************************************<br clear="none">
><br clear="none">
> Regards,<br clear="none">
> Kajod<br clear="none">
><br clear="none">
><br clear="none">
<br></div>
<br clear="none">
<br clear="none">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br clear="none">
<br clear="none">
</div>
</div>
</div>
</div>
</div>
</div>
</div></div>
</div></div><br clear="none"><br clear="none"></div> </div> </div>  </div></div></div></div></div><br><br></div> </div> </div>  </div></div></body></html>