<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:x="urn:schemas-microsoft-com:office:excel" 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=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@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:Garamond;
        panose-1:2 2 4 4 3 3 1 1 8 3;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","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.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Texte de bulles Car";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.TextedebullesCar
        {mso-style-name:"Texte de bulles Car";
        mso-style-priority:99;
        mso-style-link:"Texte de bulles";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
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=FR link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hi Joseph,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>If you take a look at the error returned, you can read that the problem comes from the ST_Intersects function which works with geometries but not with text. I think, if your geoJSON is right formatted, you can just remove the ST_AsText part and it should work.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>However it also seems that your where clause is not written correctly you can just write your query like that :<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>select ST_Asgeojson( geom ) from polys<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>where ST_Intersects(ST_GeomFromGeoJSON('$jsonPoly'), geom);<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>HTH<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hug<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>De :</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> postgis-users-bounces@lists.osgeo.org [mailto:postgis-users-bounces@lists.osgeo.org] <b>De la part de</b> Joseph Spenner<br><b>Envoyé :</b> mercredi 7 janvier 2015 17:30<br><b>À :</b> PostGIS Users Discussion<br><b>Objet :</b> Re: [postgis-users] ST_Intersects ST_GeomFromGeoJSON syntax<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div id="yui_3_16_0_1_1420642633324_35230"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'>More info.  Here are my 2 select statements.<o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_35229"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'>This one works:<o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_35228"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'><o:p> </o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34626"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'>$sth = $dbh->prepare("select ST_Asgeojson( geom ) from polys where ST_Intersects(ST_GeomFromText('POLYGON(($textPoly, $closingLon $closingLat))', 4269), geom)=TRUE");<o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34630"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'><o:p> </o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34631"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'><o:p> </o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34632"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'>However, below is my new one, which I can't get to work:<o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34633"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'><o:p> </o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34609"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'>$sth = $dbh->prepare("select ST_Asgeojson( geom ) from polys where ST_Intersects(ST_AsText(ST_GeomFromGeoJSON('$jsonPoly')), geom)=TRUE");<br><br><o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34646"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'><br><br><o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34724"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'><br><br><o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34725"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'>When I run with my new select statement, I get errors:<o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34726"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'><o:p> </o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34957"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'>-----<br><br><o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34727"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'>DBD::Pg::st execute failed: ERROR:  function st_intersects(text, geometry) is not unique<br>LINE 1: ...ertseverity,ST_Asgeojson( geom ) from polys where ST_Interse...<br>                                                             ^<br>HINT:  Could not choose a best candidate function. You might need to add explicit type casts. at ./alertPoly2.cgi line 103.<br>DBD::Pg::st execute failed: ERROR:  function st_intersects(text, geometry) is not unique<br>LINE 1: ...ertseverity,ST_Asgeojson( geom ) from polys where ST_Interse...<br>                                                             ^<br>HINT:  Could not choose a best candidate function. You might need to add explicit type casts. at ./alertPoly2.cgi line 103.<br>------<o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34959"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'><br><br><o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34961"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'>Any help would be great.<o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_35094"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'><o:p> </o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_35095"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'>Thanks!<o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_35321"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'><o:p> </o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34612"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'><o:p> </o:p></span></p><div id="yui_3_16_0_1_1420642633324_34625"><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'><o:p> </o:p></span></p></div></div><p class=MsoNormal style='background:white'><span style='font-size:10.5pt;font-family:"Garamond","serif";color:black'><o:p> </o:p></span></p><div id="yui_3_16_0_1_1420642633324_34619"><div id="yui_3_16_0_1_1420642633324_34618"><div id="yui_3_16_0_1_1420642633324_34622"><div class=MsoNormal align=center style='text-align:center;background:white'><span style='font-family:"Helvetica","sans-serif";color:black'><hr size=1 width="100%" align=center></span></div><p class=MsoNormal style='background:white'><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'>From:</span></b><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'> Hugues François <<a href="mailto:hugues.francois@irstea.fr">hugues.francois@irstea.fr</a>><br><b>To:</b> Joseph Spenner <<a href="mailto:joseph85750@yahoo.com">joseph85750@yahoo.com</a>>; PostGIS Users Discussion <<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a>> <br><b>Sent:</b> Wednesday, January 7, 2015 1:17 AM<br><b>Subject:</b> Re: [postgis-users] ST_Intersects ST_GeomFromGeoJSON syntax</span><span style='font-family:"Helvetica","sans-serif";color:black'><o:p></o:p></span></p></div><div id="yui_3_16_0_1_1420642633324_34617"><p class=MsoNormal style='margin-bottom:12.0pt;background:white'><span style='font-family:"Helvetica","sans-serif";color:black'><br>Hello,<br><br>I'm not very familiar with the use of ST_GeomFromGeoJSON() but looking at the doc, it only accepts a single json string so you'd better remove all the ST_GeomFromText stuff: ST_GeomFromGeoJSON($jsonPolys). There are some examples at the bottom of the page <a href="http://www.postgis.org/docs/ST_GeomFromGeoJSON.html">http://www.postgis.org/docs/ST_GeomFromGeoJSON.html</a>.<br><br>HTH<br><br>Hugues.<br><br><br>-------- Message d'origine--------<br>De: <a href="mailto:postgis-users-bounces@lists.osgeo.org">postgis-users-bounces@lists.osgeo.org</a> de la part de Joseph Spenner<br>Date: mar. 06/01/2015 20:31<br>À: PostGIS Users Discussion<br>Objet : [postgis-users] ST_Intersects ST_GeomFromGeoJSON syntax<br><br>Hello,I currently have a select which works correctly:<br>$sth = $dbh->prepare("select ST_Asgeojson( geom ) from polys where ST_Intersects(ST_GeomFromText('POLYGON(($textPoly, $closingLon $closingLat))', 4269), geom)=TRUE");<br><br><br>I'm trying to do the same thing, using FromGeoJSON instead of Text.  Below is my attempt, but it's not working.  This is my statement, where $jsonPolys contains the JSON:<br>$sth = $dbh->prepare("select ST_Asgeojson( geom ) from polys where ST_Intersects(ST_GeomFromGeoJSON('POLYGON(($jsonPolys))', 4269), geom)=TRUE");<br><br> I think the problem has something to do with the POLYGON text, since it may not be necessary.  But I can't get the syntax right.<br>Any ideas?<br>Thanks!<br>Regards,Joseph Spenner<br><br><o:p></o:p></span></p></div></div></div></div></div></body></html>