distance measure

Jeff Dege jdege at KORTERRA.COM
Fri May 4 12:38:13 EDT 2007


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.
 
   // r and d in km. latitudes and longitudes in radians
 
   var r = 6371;  // radius of the earth
   var d = Math.acos( Math.sin(lat1)*Math.sin(lat2) +
Math.cos(lat1)*Math.cos(lat2)*Math.cos(lon2-lon1) ) * r;
 
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.
 
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.
 



________________________________

	From: UMN MapServer Users List
[mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On Behalf Of Piero Cavalieri
	Sent: Friday, May 04, 2007 10:07 AM
	To: MAPSERVER-USERS at LISTS.UMN.EDU
	Subject: [UMN_MAPSERVER-USERS] distance measure
	
	

	Hi,

	I use jBox to calcolate distance measure.
	In jBox documentation I found this function:

	function measure_handler(name, s, t, n, a) {
	// c = 1 / 72dpi / 12inches_per_foot *
1.0003state_plane_scale_factor
	var c = 0.0011577546296296
	;    // constant
	var f = [scale] * c;           // scale factor
	if ((s>0) || (t>0)) {
	defaultStatus = "This segment = " + s*f + ", Total = " + t*f +
", Number of vertices = " + n ;
	
	}

	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: ?

	Distance = (x2 - x1)/ mapWidh * t

	 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.

	Thanks

	 Piero

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20070504/0ef70625/attachment.html


More information about the mapserver-users mailing list