<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><div>Make sure your user has limited table access. &nbsp;This example would allow for SQL injection.</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Gabriel Messner &lt;gabmessner@gmail.com&gt;<br><b><span style="font-weight: bold;">To:</span></b> mapserver-users@lists.osgeo.org<br><b><span style="font-weight: bold;">Sent:</span></b> Friday, June 26, 2009 6:51:43 AM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [mapserver-users] Spatial queries to Mapserver<br></font><br>
Thanks, IŽll digest it :-)<br><br><br><div class="gmail_quote">2009/6/26 Ben Madin <span dir="ltr">&lt;<a rel="nofollow" ymailto="mailto:ben@remoteinformation.com.au" target="_blank" href="mailto:ben@remoteinformation.com.au">ben@remoteinformation.com.au</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex;">
<div style="word-wrap:break-word;">Gabriel,<div><br></div><div>You need to add a layer with your query in it - you can use variable substitution etc.</div><div><br></div><div>an example (may or may not be a good one!) :</div>
<div><br></div><div><div>&nbsp;&nbsp; &nbsp;LAYER</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;DEBUG 3</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;NAME "buffalo"</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;GROUP "Movement"</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;METADATA</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;layer_title "Buffalo"</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;layer_order "2"</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;END</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;CONNECTIONTYPE postgis</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;CONNECTION "host=localhost port=5432 dbname=prices"</div><div><span style="white-space:pre;">                </span>PROCESSING "CLOSE_CONNECTION=DEFER"</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;DATA "route FROM (</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SELECT <a rel="nofollow" target="_blank" href="http://s.id">s.id</a>, s.commodity, s.shortname, s.amount, s.purpose, s.origprov, s.destprov, ST_MakeLine(s.startpoint, s.endpoint) as route, to_char(s.origindate,'DD/MM/YYYY') as date</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM (</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SELECT <a rel="nofollow" target="_blank" href="http://m.id">m.id</a>, c.commodity, sp.shortname, c.amount, <a rel="nofollow" target="_blank" href="http://r.name">r.name</a> AS purpose,&nbsp;</div><div>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">                </span>initcap(<a rel="nofollow" target="_blank" href="http://o.name">o.name</a>) as origprov, initcap(<a rel="nofollow" target="_blank" href="http://d.name">d.name</a>) as destprov,</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">                </span>ST_Centroid(o.geom) as startpoint, ST_Centroid(d.geom) as endpoint, origindate</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM movements m</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT OUTER JOIN locations o</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ON m.originprovince = o.hiercode</div><div>&nbsp;&nbsp; &nbsp;<span style="white-space:pre;">        </span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND o.del = 0</div>
<div><span style="white-space:pre;">        </span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND o.level = 2</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEFT OUTER JOIN locations d</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ON m.destinationprovince = d.hiercode</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">        </span>AND d.del = 0</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">        </span>AND d.level = 2</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JOIN commodities c</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ON <a rel="nofollow" target="_blank" href="http://m.id">m.id</a> = c.movementid</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">        </span>AND c.del = 0</div><div>&nbsp;&nbsp; &nbsp; &nbsp;<span style="white-space:pre;">        </span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND c.commodity = 2</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">                        </span>LEFT OUTER JOIN species sp</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">                        </span>ON c.commodity = <a rel="nofollow" target="_blank" href="http://sp.id">sp.id</a></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">                                </span>AND sp.del = 0</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">                        </span>LEFT OUTER JOIN reasons r</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">                        </span>ON c.purpose::int = <a rel="nofollow" target="_blank" href="http://r.id">r.id</a></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">                                </span>AND r.del = 0</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE m.del = 0</div>
<div><span style="white-space:pre;">                                                </span>AND originprovince is not null</div><div><span style="white-space:pre;">                                                </span>AND originprovince not like '0'</div><div><span style="white-space:pre;">                                                </span>AND destinationprovince is not null</div>
<div><span style="white-space:pre;">                                                </span>AND destinationprovince not like '0'</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;) AS s</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE s.origindate &gt; '%start%'</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">        </span> &nbsp; &nbsp; &nbsp; &nbsp;AND s.origindate &lt; '%end%'</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ORDER BY s.origindate</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;) AS foo USING UNIQUE id USING srid=4326"</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;TYPE LINE</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;STATUS ON</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;HEADER 'templates/trade_header.html'</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FOOTER 'templates/trade_footer.html'</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;CLASSITEM commodity</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;CLASS</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NAME "Buffalo"</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;EXPRESSION "2"</div><div>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;STYLE</div><div><span style="white-space:pre;">        </span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SYMBOL "arrow1"</div><div><span style="white-space:pre;">        </span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OFFSET 0 0&nbsp;</div><div>&nbsp;&nbsp; &nbsp;<span style="white-space:pre;">        </span> &nbsp; &nbsp; &nbsp; &nbsp;SIZE 12</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">        </span> &nbsp; &nbsp;COLOR 0 0 255</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space:pre;">        </span>END</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TEMPLATE 'templates/trade_query.html'</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;END</div>
<div>&nbsp;&nbsp; &nbsp;END</div><div><br></div><div><br></div><div>Actually, I don't think it's a great example, but it shows you how to create a line on the fly using the centroid (probably should have been point on surface) showing the direction the animals moved, within a user specified time frame.</div>
<div><br></div><div>I'm open to any feedback on this - it's a modification of one I modified from one Regina Obe posted somewhere.</div><div><br></div><div>I should say, note the use of debug. the error messages are invaluable when it doesn't work.</div>
<div><br></div><div>good luck</div><div><br></div><div>cheers</div><div><br></div><div>Ben</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><div>On 26/06/2009, at 2:47 PM, <a rel="nofollow" ymailto="mailto:mapserver-users-request@lists.osgeo.org" target="_blank" href="mailto:mapserver-users-request@lists.osgeo.org">mapserver-users-request@lists.osgeo.org</a> wrote:</div>
<br><blockquote type="cite"><div style="margin:0px;"><span style="font-family:Helvetica;font-size:medium;"><b>Subject:<span>&nbsp;</span></b></span><span style="font-family:Helvetica;font-size:medium;"><b>[mapserver-users] Spatial queries to Mapserver</b><br>
</span></div><div class="im"><br><br>Hi all,<br><br>Any one know of examples about how to call spatial queries using Postis functions from Mapserver?<br></div></blockquote></div><br><div> <span style="border-collapse:separate;border-spacing:0px;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;"><div style="word-wrap:break-word;">
<div style="margin:0px;">--&nbsp;</div><div style="margin:0px;min-height:14px;"><br></div><div style="margin:0px;">Ben Madin</div><div style="margin:0px;">REMOTE INFORMATION</div><div style="margin:0px;min-height:14px;">
<br></div><div style="margin:0px;">t : +61 8 9192 5455</div><div style="margin:0px;">f :&nbsp;+61 8 9192 5535</div><div style="margin:0px;">m : 0448 887 220</div><div style="margin:0px;">Broome&nbsp; &nbsp;WA&nbsp; &nbsp;6725</div><div style="margin:0px;min-height:14px;">
<br></div><div style="margin:0px;min-height:14px;"><a rel="nofollow" ymailto="mailto:ben@remoteinformation.com.au" target="_blank" href="mailto:ben@remoteinformation.com.au">ben@remoteinformation.com.au</a></div><div style="margin:0px;min-height:14px;"><br></div><div style="margin:0px;min-height:14px;">
<br></div><div style="margin:0px;min-height:14px;"><br></div><div style="margin:0px;"><span style="white-space:pre;"><span style="white-space:pre;">                                                        </span></span>Out here, it pays to know...</div></div><br></span> </div>
<br></div></div></blockquote></div><br>
</div></div><div style="position:fixed"></div></div><br>

      </body></html>