<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><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>