<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<STYLE type=text/css>DIV {
        MARGIN: 0px
}
</STYLE>

<META content="MSHTML 6.00.6000.16481" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=187402510-21052008><FONT face=Arial 
color=#0000ff size=2>Have you tried using ST_DWithin(...)  
?</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=187402510-21052008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=187402510-21052008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=187402510-21052008><FONT face=Arial 
color=#0000ff size=2>- even with Within (neither Distance nor Within 
use spatial indexes so you are essentially always doing a table scan.  
You would still need an && for those to make them use indexes.  So 
try:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=187402510-21052008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=187402510-21052008>SELECT ST_Extent(geom) as 
ext, Max(ST_Distance(geom, '<center of polygon>')) as 
max_dist</SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=187402510-21052008>FROM tarea<BR>WHERE 
 ST_DWithin(geom,'<center of polygon>', 50);</SPAN></DIV>
<DIV><SPAN class=187402510-21052008></SPAN> </DIV>
<DIV><SPAN class=187402510-21052008><FONT face=Arial color=#0000ff size=2>If you 
are using an older version of Postgis that doesn't have the ST_ (e.g. pre 
1.3)</FONT></SPAN></DIV>
<DIV><SPAN class=187402510-21052008><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=187402510-21052008><FONT face=Arial color=#0000ff size=2>Do the 
following instead</FONT></SPAN></DIV>
<DIV><SPAN class=187402510-21052008><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=187402510-21052008><FONT face=Arial color=#0000ff 
size=2></FONT> </DIV>
<DIV dir=ltr align=left><SPAN class=187402510-21052008>SELECT Extent(geom) as 
ext, Max(Distance(geom, '<center of polygon>')) as max_dist</SPAN></DIV>
<DIV dir=ltr align=left><SPAN 
class=187402510-21052008>FROM tarea<BR>WHERE  geom && 
Expand('<center of polygon>',50)  AND Distance(geom, '<center of 
polygon>') < 50;</SPAN></DIV>
<DIV><SPAN class=187402510-21052008></SPAN> </DIV>
<DIV><SPAN class=187402510-21052008><FONT face=Arial color=#0000ff size=2>Hope 
that helps,</FONT></SPAN></DIV>
<DIV><SPAN class=187402510-21052008><FONT face=Arial color=#0000ff 
size=2>Regina</FONT></SPAN></DIV>
<DIV dir=ltr align=left><BR></DIV></SPAN>
<DIV dir=ltr align=left><SPAN class=187402510-21052008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV><FONT face=Arial color=#0000ff 
size=2></FONT><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> 
postgis-users-bounces@postgis.refractions.net 
[mailto:postgis-users-bounces@postgis.refractions.net] <B>On Behalf Of </B>User 
Map<BR><B>Sent:</B> Wednesday, May 21, 2008 5:19 AM<BR><B>To:</B> PostGIS Users 
Discussion<BR><B>Subject:</B> Re: [postgis-users] extent of properties within a 
specified distance<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV 
style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<P>hi, </P>
<P>thanks, but the problem is still there, the time Distance() query is taking. 
the concept behind using within() is only to minimize the number of time the 
distance function executes. it works ok without using within() also, but the 
time is still much longer. is there any way to minimize the time it is taking to 
perform distance(), or any other way to do the same task without using 
distance().</P>
<DIV 
style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </DIV>
<DIV 
style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">regards.<BR><BR>
<DIV 
style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">----- 
Original Message ----<BR>From: Andy Anderson 
<aanderson@amherst.edu><BR>To: PostGIS Users Discussion 
<postgis-users@postgis.refractions.net><BR>Sent: Tuesday, May 20, 2008 
10:09:27 PM<BR>Subject: Re: [postgis-users] extent of properties within a 
specified distance<BR><BR>
<DIV>
<DIV><FONT class=Apple-style-span color=#000000>On May 19, 2008, at 5:01 AM, 
User Map wrote:</FONT></DIV>
<BLOCKQUOTE type="cite"><SPAN class=Apple-style-span 
  style="WORD-SPACING: 0px; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; LINE-HEIGHT: normal; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; FONT-VARIANT: normal; orphans: 2; widows: 2">
  <DIV>
  <DIV style="MARGIN: 0px">
  <DIV style="MARGIN: 0px">
  <DIV style="MARGIN: 0px">
  <P class=MsoNormal style="MARGIN: 5pt 0in"><FONT class=Apple-style-span 
  color=#000000>hi,</FONT></P>
  <P class=MsoNormal style="MARGIN: 5pt 0in"><FONT class=Apple-style-span 
  color=#000000>thanks for reply. i think i have to clarify my problem a bit 
  more. i want to get the records from my table within a specified distance for 
  e.g 50 meters. For this i have to calculate the extent first to get the image 
  in mapserver. what i have is just a polygon geom, which area as you know can 
  vary from property to property. i dont want to take into account the 
  area/distance the property holds, but a center point for that polygon, so to 
  calculate the distance equally on each side of that point, and then calculate 
  the extent of those records, for the image to be generated. what i have done 
  uptil now is:</FONT></P>
  <P class=MsoNormal style="MARGIN: 5pt 0in"><FONT class=Apple-style-span 
  color=#000000>SELECT extent(geom),max(Distance('<center of 
  polygon>',geom))as distance</FONT></P>
  <P class=MsoNormal style="MARGIN: 5pt 0in"><FONT class=Apple-style-span 
  color=#000000>from tarea</FONT></P>
  <P class=MsoNormal style="MARGIN: 5pt 0in"><FONT class=Apple-style-span 
  color=#000000>where within(geom,'<expand(geom,50)from the given 
  geom>')</FONT></P>
  <P class=MsoNormal style="MARGIN: 5pt 0in"><FONT class=Apple-style-span 
  color=#000000>and Distance('<center of polygon>',geom)<=50</FONT></P>
  <P class=MsoNormal style="MARGIN: 5pt 0in"><FONT class=Apple-style-span 
  color=#000000>but this query is taking about 25-26 mins which is quite a large 
  time span. and also when i get the results and on showing through the map 
  server, the scale bar is not matching, i mean it has to show a 100 meter bar 
  scale, but, it is showing more then 100 meters on the scalebar, about 192 or 
  so.</FONT></P></DIV></DIV></DIV></DIV></SPAN></BLOCKQUOTE><FONT 
class=Apple-style-span color=#000000><BR></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000>A couple of thoughts, upon which 
the more experienced may correct or elaborate:</FONT></DIV>
<DIV><BR></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span 
color=#000000>1) It looks to me like you are performing a duplicate calculation. 
I'm not sure if Postgres is smart enough to avoid this by itself, but just in 
case you should take advantage of a subexpression to perform the calculation 
once for each geom:</FONT></FONT></DIV>
<DIV><BR></DIV>
<DIV><FONT class=Apple-style-span color=#000000><SPAN class=Apple-tab-span 
style="WHITE-SPACE: pre"></SPAN>SELECT extent(geom), distance from (SELECT geom, 
Distance('<center of polygon>', geom)) from tarea) as tdistance where 
distance <= 50.</FONT></DIV>
<DIV><BR></DIV>
<DIV><FONT class=Apple-style-span color=#000000>2) Seems like</FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><BR></FONT></DIV>
<DIV><SPAN class=Apple-tab-span style="WHITE-SPACE: pre"><FONT 
class=Apple-style-span color=#000000></FONT></SPAN><FONT class=Apple-style-span 
color=#000000>within(geom,'<expand(geom,50)from the given 
geom>')</FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><BR></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000>is unnecessary, it will always 
be true. Or do you mean something different than the simpler form:</FONT><FONT 
class=Apple-style-span color=#000000></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><BR></FONT></DIV>
<DIV><SPAN class=Apple-tab-span style="WHITE-SPACE: pre"><FONT 
class=Apple-style-span color=#000000></FONT></SPAN><FONT class=Apple-style-span 
color=#000000>within(geom, expand(geom,50))</FONT></DIV>
<DIV><BR></DIV>
<DIV>-- Andy</DIV>
<DIV><BR></DIV></DIV></DIV></DIV><BR></BODY></HTML>

<HTML><BODY><P><hr size=1></P>
<P><STRONG>
The substance of this message, including any attachments, may be confidential, legally privileged and/or exempt from disclosure pursuant to Massachusetts law. It is intended solely for the addressee. If you received this in error, please contact the sender and delete the material from any computer.
</STRONG></P></BODY></HTML>

<P><hr size=1></P>
<P><STRONG><font size="2" color="339900"> Help make the earth a greener place. If at all possible resist printing this email and join us in saving paper. </p> <p> </font></STRONG></P>