Package sabx10 :: Package utils :: Module sabx_seg_closest
[hide private]
[frames] | no frames]

Source Code for Module sabx10.utils.sabx_seg_closest

 1  ############################################################################### 
 2  # 
 3  # sabx10 - an SABX file manipulation library 
 4  # Copyright (C) 2009, 2010 Jay Farrimond (jay@sabikerides.com) 
 5  # 
 6  # This file is part of sabx10. 
 7  # 
 8  # sabx10 is free software: you can redistribute it and/or modify it under the 
 9  # terms of the GNU General Public License as published by the Free Software 
10  # Foundation, either version 3 of the License, or (at your option) any later 
11  # version. 
12  # 
13  # sabx10 is distributed in the hope that it will be useful, but WITHOUT ANY 
14  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 
15  # A PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
16  # 
17  # You should have received a copy of the GNU General Public License along with 
18  # sabx10.  If not, see <http://www.gnu.org/licenses/>. 
19  # 
20  ############################################################################### 
21  """ 
22  Find the closest point in a segment. 
23  """ 
24   
25  from sabx10.oxm import Point 
26   
27 -def search_seg(sabx, seg_id, lat, lon):
28 """ 29 Search the indicated segment and find which waypoint is closest to the 30 given (lat,lon) point. Print the result. 31 """ 32 search_pt = Point(lat, lon) 33 shortest = 10000.0 34 for pt in sabx['seg_dict'][seg_id].waypoints: 35 dist = search_pt.calculate_distance(pt) 36 if dist < shortest: 37 shortest = dist 38 id = pt.id 39 40 print "id= %s distant = %s" % (id, shortest)
41