<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><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;}
/* 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;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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]-->
<style type="text/css">body { font-family:'DejaVu Sans Mono'; font-size:12px}</style>
</head>
<body lang="EN-GB" link="blue" vlink="purple"><div>You could use DWithin: http://blog.cleverelephant.ca/2010_08_01_archive.html</div><div>Because your geometries are in 4326, you can cast the them and the point to geography (without ST_transform) and then use DWithin:</div><div><br></div><div>WHERE ST_DWithin(parcels.geom::geography, yourpoint::geography, 100)</div><div><br></div><div>Regards Tommaso</div><div><br></div><div><br></div><div><br></div><div>On Wed, 09 Jul 2014 09:25:59 +0200, Guido Lemoine <guido.lemoine@jrc.ec.europa.eu> wrote:<br></div><br><blockquote style="margin: 0 0 0.80ex; border-left: #0000FF 2px solid; padding-left: 1ex"><div class="WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Alexander,</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 style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">You would want to check out ST_BUFFER, which is doing what you intend to do.</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 style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Guido</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 style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p><p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> postgis-users-bounces@lists.osgeo.org [mailto:postgis-users-bounces@lists.osgeo.org] <b>On Behalf Of </b>Alexander W. Rolek<br><b>Sent:</b> 09 July 2014 05:36<br><b>To:</b> postgis-users@lists.osgeo.org; Jeffrey Johnson<br><b>Subject:</b> [postgis-users] Finding records withing XX distance from a geometry in the same table</span></p><p class="MsoNormal"><o:p> </o:p></p><div><p class="MsoNormal">I'm trying to query all the records within XX distance from a geometry. I would like to be able to reference the subject geometry via it's id, and then find every geometry that is either:</p><div><p class="MsoNormal"><o:p> </o:p></p></div><div><p class="MsoNormal">A) within XX distance from a x/y coordinate of the geometry</p></div><div><p class="MsoNormal">B) within XX distance from the edge of the geometry on all sides. (ideal)</p></div><div><p class="MsoNormal"><o:p> </o:p></p></div><div><p class="MsoNormal">What is the best way to accomplish this? My current query:</p></div><div><p class="MsoNormal"><o:p> </o:p></p></div><div><div><p class="MsoNormal">SELECT *</p></div><div><p class="MsoNormal">            FROM sdgis.parcels4326 AS parcels</p></div><div><p class="MsoNormal">            WHERE ST_Distance_Sphere(</p></div><div><p class="MsoNormal">                        parcels.geom,</p></div><div><p class="MsoNormal">                        ST_Transform(ST_SetSRID(ST_MakePoint('6255896.314288','1898596.929109'),2230),4326)</p></div><div><p class="MsoNormal">            ) < 100.0;</p></div><div><p class="MsoNormal"><o:p> </o:p></p></div><div><p class="MsoNormal">This takes a few minutes to run on a table with just over 1 million records. I would like to swap out the ST_MakePoint, with a multipolygon from a record that is looked up via it's id. </p></div><div><p class="MsoNormal"><o:p> </o:p></p></div><div><p class="MsoNormal">Any suggestions are greatly appreciated.</p></div><div><div><p class="MsoNormal"><o:p> </o:p></p></div><p class="MsoNormal" style="margin-bottom:12.0pt">-- <br>Alexander W. Rolek</p></div></div></div></div></blockquote><br><br><br><div id="M2Signature"><div>-- </div><div>Using Opera's mail client: <a href="http://www.opera.com/mail/">http://www.opera.com/mail/</a></div></div></body></html>