<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2800.1589" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT color=#0000ff size=2><SPAN 
class=992531416-04052007>These linear formulas are only accurate at tight zooms 
- maps of cities.&nbsp; When you're dealing with maps of countries or states, 
you're going to have to use spherical geometry.&nbsp; The formulas for spherical 
distance for coordinates expressed in lat/long are well known.&nbsp; But you 
need to reverse the projection, converting the points to 
lat/long.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007><FONT color=#0000ff 
size=2>&nbsp;&nbsp; //&nbsp;r and d in km. latitudes and longitudes in 
radians</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007></SPAN><SPAN 
class=992531416-04052007><FONT color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007><FONT color=#0000ff 
size=2>&nbsp;&nbsp; var&nbsp;r = 6371;&nbsp; //&nbsp;radius of the 
earth</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007><FONT color=#0000ff 
size=2>&nbsp;&nbsp; var d = Math.acos( Math.sin(lat1)*Math.sin(lat2) 
+&nbsp;Math.cos(lat1)*Math.cos(lat2)*Math.cos(lon2-lon1) ) * 
r;</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007><FONT color=#0000ff 
size=2>Of course, if you want real precision, you'l want to use an ellipsoid, 
instead of a sphere, but then you're getting into which ellipsoid is defined for 
the datum you're using, and it starts to get hairy, again.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007><FONT color=#0000ff 
size=2>Me, I'd run the numbers for the largest distance you're likely to 
measure, once for linear distance and once for spherical distances, and see how 
far apart they are.&nbsp; Then you can judge whether the complexity of the 
spherical calculations&nbsp;is needed.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007><FONT color=#0000ff 
size=2>&nbsp;</DIV></FONT></SPAN><FONT color=#0000ff size=2></FONT><FONT 
color=#0000ff size=2></FONT><FONT color=#0000ff size=2></FONT><BR>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
  <HR tabIndex=-1>
  <FONT face=Tahoma size=2><B>From:</B> UMN MapServer Users List 
  [mailto:MAPSERVER-USERS@LISTS.UMN.EDU] <B>On Behalf Of </B>Piero 
  Cavalieri<BR><B>Sent:</B> Friday, May 04, 2007 10:07 AM<BR><B>To:</B> 
  MAPSERVER-USERS@LISTS.UMN.EDU<BR><B>Subject:</B> [UMN_MAPSERVER-USERS] 
  distance measure<BR></FONT><BR></DIV>
  <DIV></DIV>
  <P class=MsoNormal><SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Hi,</SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-GB 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">I use jBox to calcolate distance 
  measure.<BR>In jBox documentation I found this function:</SPAN></P><PRE><SPAN lang=EN-GB>function measure_handler(name, s, t, n, a) {<SPAN><BR></SPAN>// c = 1 / 72dpi / 12inches_per_foot * 1.0003state_plane_scale_factor<SPAN><BR></SPAN>var c = 0.0011577546296296
;<SPAN>&nbsp;&nbsp;&nbsp; </SPAN>// constant<SPAN><BR></SPAN>var f = [scale] * c;<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>// scale factor<SPAN><BR></SPAN>if ((s&gt;0) || (t&gt;0)) {<SPAN><BR></SPAN>defaultStatus = "This segment = " + s*f + ", Total = " + t*f + ", Number of vertices = " + n ;
<SPAN><BR></SPAN></SPAN>}</PRE>
  <P class=MsoNormal><SPAN lang=EN-GB 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Since I'm not able to have user 
  dpi (and 72 is a mean value, I suppose), isn't more correct (and simpler) to 
  use this way: ?</SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-GB 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Distance = (x2 &#8211; x1)/ mapWidh * 
  t</SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-GB 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;Where x2 and x1 are 
  mapextents in real world coordinates, as returned in imgext, mapWidth is the 
  width in pixel, as specified in .map file (and returned in template file), and 
  t is the jBox meaure, in pixel.</SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-GB 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Thanks</SPAN></P>
  <P class=MsoNormal><SPAN lang=EN-GB 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN>&nbsp;</SPAN>Piero</SPAN></P></BLOCKQUOTE></BODY></HTML>