<!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=644580513-21052008><FONT face=Arial 
color=#0000ff size=2>That question would probably be better to ask in the 
mapserver list.  The scale bar in mapserver is dependent on a number of 
things.  Which the following come to mind at the moment</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2>1) What do you have your map projection init set to for the 
map.  I presume you have something like</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2>MAP ...</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2>PROJECTION<BR> "init=epsg:<FONT face="Times New Roman" 
color=#000000>27700</FONT>"<BR>END</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2>epsg:27700 has to be defined in your proj file and if it 
isn't you have to put the whole proj4text in projection or add it to your 
file - which my mind escapes me how to do that.  I think you can 
pretty much copy the proj4text from the spatial_ref_sys</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2>2) Your SCALEBAR section must say meters - something like 
</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2>SCALEBAR<BR>  STATUS embed<BR>  INTERVALS 
3<BR>  SIZE 200 2<BR>  COLOR 0 0 0<BR>  OUTLINECOLOR 0 0 
0<BR>  UNITS meters<BR>  LABEL<BR>    COLOR 0 0 
0<BR>    SIZE small<BR>  END<BR>  TRANSPARENT 
ON<BR>END</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2>hope that helps,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2>Regina</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=644580513-21052008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV><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 8:27 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">
<DIV 
style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><FONT 
size=2>
<P>hi there,</P>
<P>thanks for the immediate reply. i have tried what you have suggested, and its 
now taking no more longer time spans :) but i dont know how it is calculating 
the distance, because the extent returned by the query when used in the mapfile 
for mapserver with a scalebar, it is giving much larger area of about 800m in 
total, which should be about 100 m in actual as defined in the query.</P>
<P>i have this query</P>
<P>________________________________________________________________________</P>
<P>SELECT ST_Extent(geom) as ext, count 
(*),Max(Distance(geom,GeomFromText('POINT(530525.056494402 
191742.597993273)',27700))) as max_dist</P>
<P>FROM tarea</P>
<P>WHERE ST_DWithin(geom,GeomFromText('POINT(530525.056494402 
191742.597993273)',27700), 50)</P>
<P>__________________________________________________________________________</P>
<P>POINT(530525.056494402 191742.597993273) is got from 
AsText(Centroid(geom))</P>
<P>i have OSGB36 data, and srid= 27700, which i have set in the query. </P>
<P>the extent returned is much larger. but the max_dist is returning 49.5, which 
is fine.</P>
<P>do you know why it is not matching the scalebar in the mapserver. does the 
mapserver scalebar works differently then the Distance query.</P>
<P>any help will be appriciated</P>
<P>regards</P></FONT><BR><BR>
<DIV 
style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">----- 
Original Message ----<BR>From: "Obe, Regina" 
<robe.dnd@cityofboston.gov><BR>To: PostGIS Users Discussion 
<postgis-users@postgis.refractions.net><BR>Sent: Wednesday, May 21, 2008 
11:38:57 AM<BR>Subject: RE: [postgis-users] extent of properties within a 
specified distance<BR><BR>
<STYLE type=text/css>DIV {
        MARGIN: 0px
}
</STYLE>

<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>
<P>
<HR SIZE=1>

<P></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>
<P>
<HR SIZE=1>

<P></P>
<P><STRONG><FONT color=#339900 size=2>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></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>