<!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. When you're dealing with maps of countries or states,
you're going to have to use spherical geometry. The formulas for spherical
distance for coordinates expressed in lat/long are well known. 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> </DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007><FONT color=#0000ff
size=2> // 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> </DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007><FONT color=#0000ff
size=2> var r = 6371; // radius of the
earth</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007><FONT color=#0000ff
size=2> var d = Math.acos( Math.sin(lat1)*Math.sin(lat2)
+ 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> </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> </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. Then you can judge whether the complexity of the
spherical calculations is needed.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992531416-04052007><FONT color=#0000ff
size=2> </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> </SPAN>// constant<SPAN><BR></SPAN>var f = [scale] * c;<SPAN> </SPAN>// scale factor<SPAN><BR></SPAN>if ((s>0) || (t>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 – x1)/ mapWidh *
t</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-GB
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 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> </SPAN>Piero</SPAN></P></BLOCKQUOTE></BODY></HTML>