<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><DIV><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 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-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 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-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 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-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; ">You want to use the Distance function in the result set:<BR class="Apple-interchange-newline"></SPAN></SPAN></SPAN> </DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>SELECT location_id, Distance(point_geom, MakePoint(-117.13538, 32.6857)) FROM table;</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>You don't need a WHERE clause unless you want to restrict the result rows (for example, if you wanted to limit the results to locations within 50 miles of the target point).</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>I would suggest reviewing the PostgreSQL documentation for some basic SQL instruction (at <A href="http://www.postgresql.org/docs/">http://www.postgresql.org/docs/</A>; the manual is actually very good). Then you can refer to the PostGIS reference (<A href="http://postgis.refractions.net/docs/ch06.html">http://postgis.refractions.net/docs/ch06.html</A>) for a list of functions.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>You really don't need a lot of knowledge on top of PostgreSQL to use PostGIS effectively. Most everything that seems confusing or vague about the PostGIS documentation can be clarified by reading the OpenGIS specs, at <A href="http://www.opengeospatial.org/standards/sfa">http://www.opengeospatial.org/standards/sfa</A> and <A href="http://www.opengeospatial.org/standards/sfb">http://www.opengeospatial.org/standards/sfb</A>.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>And you can always ask on postgis-users if you need clarification.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Hope this helps,</DIV><DIV>Brad</DIV><BR><DIV><DIV>On Dec 30, 2006, at 12:10 AM, Adam wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"> <DIV><FONT face="Arial" size="2">I've tried:</FONT></DIV> <DIV><FONT face="Arial" size="2"></FONT> </DIV> <DIV><FONT face="Arial" size="2">SELECT point_geom, location_id<BR> FROM locations<BR> WHERE Distance(point_geom, 'POINT(-117.13538 32.6857)')<BR></FONT></DIV> <DIV><FONT face="Arial" size="2">But get error: argument of WHERE must be type boolean, not type double precision</FONT></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><FONT face="Arial" size="2"></FONT> <BR class="khtml-block-placeholder"></DIV><BLOCKQUOTE style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px"> <DIV style="FONT: 10pt arial">----- Original Message ----- </DIV> <DIV style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> <A title="adam@spatialsystems.org" href="mailto:adam@spatialsystems.org">Adam</A> </DIV> <DIV style="FONT: 10pt arial"><B>To:</B> <A title="postgis-users@postgis.refractions.net" href="mailto:postgis-users@postgis.refractions.net">PostGIS Users Discussion</A> </DIV> <DIV style="FONT: 10pt arial"><B>Sent:</B> Saturday, December 30, 2006 12:07 AM</DIV> <DIV style="FONT: 10pt arial"><B>Subject:</B> [postgis-users] Finding Points with distance to a location.</DIV> <DIV><BR></DIV> <DIV><FONT face="Arial" size="2">I figured this out last year, but can't figure out how I figured it out. I've read "Mapping Hacks" and "Web Mapping Illustrated" along with what I could find in the WIKI and documentation but can't start to figure it out.</FONT></DIV> <DIV><FONT face="Arial" size="2"></FONT> </DIV> <DIV><FONT face="Arial" size="2">I have my geometry column named "point_geom" and a unique column named "location_id".</FONT></DIV> <DIV><FONT face="Arial" size="2"></FONT> </DIV> <DIV><FONT face="Arial" size="2">I want to query the distance of all the points in my "point_geom" column to coords: Long = -117.13538 :: Lat = 32.6857</FONT></DIV> <DIV><FONT face="Arial" size="2"></FONT> </DIV> <DIV><FONT face="Arial" size="2"><STRONG>What would the query for this look like? Is there a comprehensive article or book out that goes in depth into how spatial queries work?</STRONG></FONT></DIV> <DIV><FONT face="Arial" size="2"></FONT> </DIV> <DIV><FONT face="Arial" size="2">The output would look like this:</FONT></DIV> <DIV><FONT face="Arial" size="2"></FONT> </DIV> <DIV><FONT face="Arial" size="2">location_id | distance</FONT></DIV> <DIV><FONT face="Arial" size="2">-------------------------------</FONT></DIV> <DIV><FONT face="Arial" size="2">5 | 45.38823</FONT></DIV> <DIV><FONT face="Arial" size="2">9 | 50.39952</FONT></DIV> <DIV><FONT face="Arial" size="2">1 | 82.39923</FONT></DIV> <DIV><FONT face="Arial" size="2">.</FONT></DIV> <DIV><FONT face="Arial" size="2">.</FONT></DIV> <DIV><FONT face="Arial" size="2">.</FONT></DIV> <DIV><FONT face="Arial" size="2">-------------------------------</FONT></DIV> <DIV><FONT face="Arial" size="2"></FONT> </DIV> <DIV><FONT face="Arial" size="2"></FONT> </DIV> <DIV><FONT face="Arial" size="2">I'm guessing that you'd use distance_spheroid for the calculation. </FONT></DIV> <DIV><FONT face="Arial" size="2"></FONT> </DIV> <DIV><FONT face="Arial" size="2"></FONT> </DIV><DIV> <BR class="khtml-block-placeholder"></DIV><HR><DIV><BR class="khtml-block-placeholder"></DIV>_______________________________________________<BR>postgis-users mailing list<BR><A href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</A><BR>http://postgis.refractions.net/mailman/listinfo/postgis-users<BR></BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">postgis-users mailing list</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users</A></DIV> </BLOCKQUOTE></DIV><BR></BODY></HTML>