<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Plain Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.5pt;
        font-family:Consolas;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.PlainTextChar
        {mso-style-name:"Plain Text Char";
        mso-style-priority:99;
        mso-style-link:"Plain Text";
        font-family:Consolas;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
span.EmailStyle21
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle22
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle23
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle24
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle25
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle26
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Sally Buechel [mailto:swbuechel@comcast.net]
<br>
<b>Sent:</b> Friday, September 13, 2013 3:39 PM<br>
<b>To:</b> Fawcett, David (MNIT)<br>
<b>Subject:</b> RE: [mapserver-users] problem with INTERSECTS query from OpenLayers to mapserver<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:#1F497D">Here are the POST queries output by OpenLayers and the wfs part of the mapfile its using if that helps (am also interested in confirming just that this general concept works, that someone is actually doing it
 successfully):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoPlainText" style="margin-bottom:12.0pt"><span style="font-family:"Courier New"">Example of the POST request for a non-spatial query which works<br>
<br>
<wfs:GetFeature xmlns:wfs="<a href="http://www.opengis.net/wfs">http://www.opengis.net/wfs</a>" service="WFS" version="1.0.0" maxFeatures="50" xsi:schemaLocation="<a href="http://www.opengis.net/wfs%20http:/schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd">http://www.opengis.net/wfs
 http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd</a>" xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"><br>
<wfs:Query typeName="feature:mytable"><br>
<ogc:Filter xmlns:ogc="<a href="http://www.opengis.net/ogc">http://www.opengis.net/ogc</a>"><br>
<ogc:And><br>
<ogc:PropertyIsLessThan><br>
<ogc:PropertyName>attr2</ogc:PropertyName><br>
<ogc:Literal>5</ogc:Literal><br>
</ogc:PropertyIsLessThan><br>
<ogc:PropertyIsEqualTo><br>
<ogc:PropertyName>attr3</ogc:PropertyName><br>
<ogc:Literal>78008</ogc:Literal><br>
</ogc:PropertyIsEqualTo><br>
</ogc:And><br>
</ogc:Filter><br>
</wfs:Query><br>
</wfs:GetFeature><br>
<br>
Example of the POST for the spatial INTERSECTS query which fails:<br>
<br>
<wfs:GetFeature xmlns:wfs="<a href="http://www.opengis.net/wfs">http://www.opengis.net/wfs</a>" service="WFS" version="1.0.0" maxFeatures="50" xsi:schemaLocation="<a href="http://www.opengis.net/wfs%20http:/schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd">http://www.opengis.net/wfs
 http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd</a>" xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"><br>
<wfs:Query typeName="feature:mytable"><br>
<ogc:Filter xmlns:ogc="<a href="http://www.opengis.net/ogc">http://www.opengis.net/ogc</a>"><br>
<ogc:And><br>
<ogc:Intersects><br>
<ogc:PropertyName>attr1</ogc:PropertyName><br>
<gml:Polygon xmlns:gml="<a href="http://www.opengis.net/gml">http://www.opengis.net/gml</a>" srsName="EPSG:4326"><br>
<gml:outerBoundaryIs><br>
<gml:LinearRing><br>
<gml:coordinates decimal="." cs="," ts=" ">-166.8375,69.723751831055 -168.75,63.311251831055 -166.3875,60.273751831055 -160.3125,57.573751831055 -155.5875,59.036251831055 -153.5625,62.748751831055 -156.6,66.911251831055 -166.8375,69.723751831055</gml:coordinates><br>
</gml:LinearRing><br>
</gml:outerBoundaryIs><br>
</gml:Polygon><br>
</ogc:Intersects><br>
<ogc:PropertyIsEqualTo><br>
<ogc:PropertyName>attr2</ogc:PropertyName><br>
<ogc:Literal>5</ogc:Literal><br>
</ogc:PropertyIsEqualTo><br>
</ogc:And><br>
</ogc:Filter><br>
</wfs:Query><br>
</wfs:GetFeature><br>
<br>
Response from failed Spatial query:<br>
<br>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><br>
<html><head><br>
<title>500 Internal Server Error</title><br>
</head><body><br>
<h1>Internal Server Error</h1><br>
<p>The server encountered an internal error or<br>
misconfiguration and was unable to complete<br>
your request.</p><br>
<p>Please contact the server administrator,<br>
root@localhost and inform them of the time the error occurred,<br>
and anything you might have done that may have<br>
caused the error.</p><br>
<p>More information about this error may be available<br>
in the server error log.</p><br>
<hr><br>
<address>Apache Server at localhost Port 80</address><br>
</body></html><br>
<br>
Apache error log:<br>
[Fri Sep 13 01:49:34 2013] [error] [client 127.0.0.1] Premature end of script headers: mapserv, referer:
<a href="http://localhost/testol6_7w.html">http://localhost/testol6_7w.html</a><br>
<br>
WFS part of Mapfile (note this mapfile works using shp2img when a FILTER is added to it):<o:p></o:p></span></p>
<p class="MsoPlainText" style="margin-bottom:12.0pt"><span style="font-family:"Courier New"">MAP<o:p></o:p></span></p>
<p class="MsoPlainText" style="margin-bottom:12.0pt"><span style="font-family:"Courier New""><clipped out part><br>
#<br>
# Set up WFS layer for feeding data to OpenLayers front-end<br>
LAYER<br>
   NAME "mytable"<br>
   TYPE Polygon<br>
   STATUS ON<br>
   DUMP true #added 8/13 can't remember if needed...<br>
   CONNECTIONTYPE postgis<br>
   CONNECTION "host='localhost' dbname='test' user='user1' port=5432"<br>
   PROCESSING "CLOSE_CONNECTION=DEFER"<br>
   # need geometry, doesn't work for geography trying to cast it<br>
   # this worked for mapserver<br>
   DATA "attr1 from mytable USING UNIQUE gid USING srid=4326"<br>
   METADATA<br>
     "wfs_title"   "My_WFS"<br>
     "wfs_version" "1.0.0"<br>
     "wfs_extent" "-180.00 -89.99 180.00 89.99"<br>
     "gml_include_items" "all"<br>
     "gml_featureid" "gid"<br>
     "wfs_enable_request"  "*"<br>
   END<br>
   CLASS<br>
      NAME 'Attr1'<br>
      STYLE<br>
          COLOR -1 -1 -1<br>
          OUTLINECOLOR 0 255 0<br>
      END<br>
   END # end attr1 class<br>
   PROJECTION<br>
       "init=epsg:4326"<br>
   END<br>
END #query layer<br>
<br>
END #end map<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Fawcett, David (MNIT) [<a href="mailto:David.Fawcett@state.mn.us">mailto:David.Fawcett@state.mn.us</a>]
<br>
<b>Sent:</b> Friday, September 13, 2013 12:15 PM<br>
<b>To:</b> Sally Buechel; <a href="mailto:mapserver-users@lists.osgeo.org">mapserver-users@lists.osgeo.org</a><br>
<b>Subject:</b> RE: [mapserver-users] problem with INTERSECTS query from OpenLayers to mapserver<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:#1F497D">Sally, <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">To make it easier for people to help you figure this out, I would suggest including the request string produced by OpenLayers and your mapfile text. 
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">David.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">
<a href="mailto:mapserver-users-bounces@lists.osgeo.org">mapserver-users-bounces@lists.osgeo.org</a>
<a href="mailto:[mailto:mapserver-users-bounces@lists.osgeo.org]">[mailto:mapserver-users-bounces@lists.osgeo.org]</a>
<b>On Behalf Of </b>Sally Buechel<br>
<b>Sent:</b> Friday, September 13, 2013 1:54 PM<br>
<b>To:</b> <a href="mailto:mapserver-users@lists.osgeo.org">mapserver-users@lists.osgeo.org</a><br>
<b>Subject:</b> [mapserver-users] problem with INTERSECTS query from OpenLayers to mapserver<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Am hoping someone can help or at least point me in the right direction regarding a problem I’m having trying to send a spatial filter produced in OpenLayers to mapserver.  What I’m trying to do is so basic, I’m sure that many have done
 this, yet I’ve been unsuccessful.  I thought this would be easy.  With much searching I have found similar questions, but nothing actually answering or showing a working example of this.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’m using mapserver 6.2.1 and the current OpenLayers.js.  I can run the wfs.map file using shp2img and get a valid response from mapserver, I can run non-spatial filters using my OpenLayers WFS call to mapserver.  The POST request sent
 to mapserver with the spatial query looks fine, but I simply get  the not very helpful “premature end of script headers : mapserv” in response.  The spatial input is a hand-drawn polygon in OpenLayers and the intersection at the mapserver end is a postgis
 table containing a polygon field.  The table is large, but a spatial restriction should always yield a manageable number of records.  Without a spatial restriction in the filter, I’ve noticed that mapserver tried to load all the data, so have currently restricted
 it to 100 records for testing/debugging.  I’m assuming once I get the spatial filter that this will restrict the number of records retrieved on the server side.  I have some assumptions, but as I said I’ve not been able to find a working example of this online,
 maybe because its too simple and everyone but me has it working?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Should what I’m trying to do work or am I just beating my head against the wall?  It doesn’t seem that this should be so hard…<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Sally<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>