<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:v = 
"urn:schemas-microsoft-com:vml" xmlns:o = 
"urn:schemas-microsoft-com:office:office" xmlns:w = 
"urn:schemas-microsoft-com:office:word" xmlns:m = 
"http://schemas.microsoft.com/office/2004/12/omml"><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16414" name=GENERATOR><!--[if !mso]>
<STYLE>v\:* {
        BEHAVIOR: url(#default#VML)
}
o\:* {
        BEHAVIOR: url(#default#VML)
}
w\:* {
        BEHAVIOR: url(#default#VML)
}
.shape {
        BEHAVIOR: url(#default#VML)
}
</STYLE>
<![endif]-->
<STYLE>@font-face {
        font-family: Cambria Math;
}
@font-face {
        font-family: Calibri;
}
@font-face {
        font-family: Tahoma;
}
@page Section1 {size: 612.0pt 792.0pt; margin: 70.85pt 3.0cm 70.85pt 3.0cm; }
P.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
LI.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
DIV.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
P {
        FONT-SIZE: 12pt; MARGIN-LEFT: 0cm; MARGIN-RIGHT: 0cm; FONT-FAMILY: "Times New Roman","serif"; mso-style-priority: 99; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto
}
SPAN.EmailStyle17 {
        COLOR: windowtext; FONT-FAMILY: "Calibri","sans-serif"; mso-style-type: personal
}
SPAN.EmailStyle20 {
        COLOR: #1f497d; FONT-FAMILY: "Calibri","sans-serif"; mso-style-type: personal-reply
}
.MsoChpDefault {
        FONT-SIZE: 10pt; mso-style-type: export-only
}
DIV.Section1 {
        page: Section1
}
</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]--></HEAD>
<BODY lang=PT vLink=purple link=blue>
<DIV dir=ltr align=left><SPAN class=502383513-02042007><FONT face=Arial 
color=#0000ff size=2>Its whatever the metric of your r.geometry field so if 
that is in degrees then yes it would be in degrees.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=502383513-02042007><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=502383513-02042007><FONT face=Arial 
color=#0000ff size=2>Thanks,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=502383513-02042007><FONT face=Arial 
color=#0000ff size=2>Regina</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>Pedro 
Doria Meunier<BR><B>Sent:</B> Monday, April 02, 2007 9:32 AM<BR><B>To:</B> 
'PostGIS Users Discussion'<BR><B>Subject:</B> RE: [postgis-users] 10 closest 
units<BR><B>Importance:</B> High<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV class=Section1>
<P class=MsoNormal><SPAN style="COLOR: #1f497d">Regina,<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="COLOR: #1f497d"><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="COLOR: #1f497d">You’re simply an 
angel! Thank you!<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US 
style="COLOR: #1f497d"><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="COLOR: #1f497d">Just one 
question:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="COLOR: #1f497d">The 
expand(rc.agg_geometry, 0.5) uses *<B>degrees</B>*, right?<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US 
style="COLOR: #1f497d"><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="COLOR: #1f497d">All the 
best,<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US 
style="COLOR: #1f497d">Pedro.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US 
style="COLOR: #1f497d"><o:p> </o:p></SPAN></P>
<DIV>
<DIV 
style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; PADDING-TOP: 3pt; BORDER-BOTTOM: medium none">
<P class=MsoNormal><B><SPAN lang=EN-US 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">From:</SPAN></B><SPAN 
lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'"> 
postgis-users-bounces@postgis.refractions.net 
[mailto:postgis-users-bounces@postgis.refractions.net] <B>On Behalf Of </B>Obe, 
Regina<BR><B>Sent:</B> segunda-feira, 2 de Abril de 2007 13:43<BR><B>To:</B> 
PostGIS Users Discussion<BR><B>Subject:</B> RE: [postgis-users] 10 closest 
units<o:p></o:p></SPAN></P></DIV></DIV>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal><SPAN 
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'">I'm not 
sure how slow this would be depending on how many line segments you have by 
name, but it seems the most speedy to write.  Basically I think you want to 
collect all your roads of N17 into a single geometry so that you can then apply 
a single distance check call.</SPAN><SPAN 
style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"> <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'">So 
something like</SPAN><SPAN 
style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"> <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="COLOR: blue">select u.friendly_name, 
distance(transform(u.curr_location, 32628), <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US 
style="COLOR: blue">transform(rc.agg_geometry,32628)) as thedistance 
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="COLOR: blue">from (SELECT 
collect(r.geometry) as agg_geometry FROM pt_mainland_roads r WHERE r.name = 
'N17') rc, units as u <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="COLOR: blue">where 
rc.agg_geometry && u.curr_location order by thedistance LIMIT 
10;</SPAN><o:p></o:p></P>
<P class=MsoNormal> <o:p></o:p></P>
<P class=MsoNormal><SPAN lang=EN-US style="COLOR: blue">If you have some units 
that are not in the bounding box of a road that would be in the top 10, then you 
may want to change your where clause to</SPAN><SPAN 
lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal> <SPAN lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="COLOR: blue">expand(rc.agg_geometry, 
<somevalue>)&& u.curr_location </SPAN><SPAN 
lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal> <SPAN lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="COLOR: blue">Hope that 
helps,</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="COLOR: blue">Regina</SPAN><SPAN 
lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"><o:p> </o:p></SPAN></P>
<DIV class=MsoNormal style="TEXT-ALIGN: center" align=center><SPAN lang=EN-US 
style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'">
<HR align=center width="100%" SIZE=2>
</SPAN></DIV>
<P class=MsoNormal style="MARGIN-BOTTOM: 12pt"><B><SPAN lang=EN-US 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">From:</SPAN></B><SPAN 
lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'"> 
postgis-users-bounces@postgis.refractions.net 
[mailto:postgis-users-bounces@postgis.refractions.net] <B>On Behalf Of </B>Pedro 
Doria Meunier<BR><B>Sent:</B> Sunday, April 01, 2007 9:50 PM<BR><B>To:</B> 
'PostGIS Users Discussion'<BR><B>Subject:</B> [postgis-users] 10 closest 
units<BR><B>Importance:</B> High</SPAN><SPAN lang=EN-US 
style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"><o:p></o:p></SPAN></P>
<P class=MsoNormal>Hi All,<o:p></o:p></P>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal><SPAN lang=EN-US>@Regina:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>Remember you helped me with the 10 closest 
units to a given point? This was it:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>(original layers srid==4326 – I want 
*<B>meters</B>* so the transform at play)<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>SELECT u.id, u.friendly_name, 
u.curr_location, t.oid, distance(transform(u.curr_location,32628), 
transform(t.geometry, 32628)) AS thedistance, u.mobile FROM units AS u, (SELECT 
roads.oid, roads.geometry FROM roads WHERE name=’N17’ LIMIT 1) AS t 
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>ORDER BY thedistance LIMIT 
10;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>(this query returns the 1<SUP>st</SUP> found 
line segment labelled ‘N17’ which is 68Kms away when the unit is actually 1.8 
meters away from the closest line segment of the same 
label)<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>@All<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>This actually returns the FIRST occurrence 
of ‘N17’ (the sample).<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>This is *<B>NOT</B>* necessarily the closest 
road to the unit’s current location.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>I’ve melted half-a-dozen neurons (mainly due 
to tiredness at the time of this writing :] )trying to figure out how can I 
implement the distance bit in the sub-query…<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>Given example for ONE 
unit:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>select u.friendly_name, 
distance(transform(u.curr_location, 32628), <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>transform(geometry,32628)) as thedistance 
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>from pt_mainland_roads as r, units as u 
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>where name='N17' AND u.curr_location 
&& r.geometry order by thedistance LIMIT 1;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>(this returns the correct 
result)<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>So to summarize 
things:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>I need help with a query that returns the 
*<B>FIRST TEN</B>* units to the *<B>closest given</B>* road. 
<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>(Keep in mind that multiple line segments 
with the same name exist – I need the closest)<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>Will try again tomorrow with a clear head 
but in the meantime:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>Any help would be most 
appreciated!<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>Best regards,<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>Pedro Doria Meunier.<o:p></o:p></SPAN></P>
<DIV class=MsoNormal style="TEXT-ALIGN: center" align=center><SPAN 
style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'">
<HR align=center width="100%" SIZE=1>
</SPAN></DIV>
<P class=MsoNormal><SPAN 
style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"><o:p> </o:p></SPAN></P>
<P><B><BR><STRONG>The substance of this message, including any attachments, may 
be</STRONG><BR><STRONG>confidential, legally privileged and/or exempt from 
disclosure</STRONG><BR><STRONG>pursuant to Massachusetts law. It is intended 
solely for the</STRONG><BR><STRONG>addressee. If you received this in error, 
please contact the sender</STRONG><BR><STRONG>and delete the material from any 
computer.</STRONG></B><o:p></o:p></P></DIV></BODY></HTML>