[OpenLayers-Trac] [OpenLayers] #173: path measuring tool

OpenLayers trac at openlayers.org
Wed Feb 21 21:24:06 EST 2007


#173: path measuring tool
-----------------------------------+----------------------------------------
  Reporter:  jrf                   |       Owner:             
      Type:  feature               |      Status:  new        
  Priority:  blocker               |   Milestone:  2.4 Release
 Component:  Control.MouseToolbar  |     Version:             
Resolution:                        |    Keywords:             
-----------------------------------+----------------------------------------
Comment (by jrf):

 Regarding error:  off the top of my head, 5% error at 1:1000 scale seems
 like a good target.

 Computing distance between points usually requires getting unprojected
 spherical coordinates, which is trivial for epsg:4326 and for layers that
 offer pixel-to-lon-lat methods.  For layers that do not offer such a
 method, the path measuring tool simply won't work.  That's is acceptable
 (to me) for this release.


 Here's some python for computing the distance.  I'm sure similar is
 generically available in javascript.

 {{{
 import math

 earth_radius = 6372.795  # radius of the earth in kilometers

 def point_point_distance(lon1, lat1, lon2, lat2):
     """compute distance from one spherical coordinate location to another;
        input measured in degrees; output in kilometers"""
     lat1 = float(lat1) * math.pi / 180.0  # convert to radians
     lon1 = float(lon1) * math.pi / 180.0
     lat2 = float(lat2) * math.pi / 180.0
     lon2 = float(lon2) * math.pi / 180.0
     radians = 2 * math.asin(math.sqrt(math.sin((lat1 - lat2)/2)**2 + \
                                       math.cos(lat1) * math.cos(lat2) * \
                                       math.sin((lon1 - lon2)/2)**2))

     return radians * earth_radius

 }}}

-- 
Ticket URL: <http://trac.openlayers.org/ticket/173#comment:6>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer


More information about the Trac mailing list