def _process_lat_lon(self, lat, lon): """ Get the lat, lon, and waypoint corresponding to the lat and lon values passed in. If lat contains a point id, then the corresponding point is found. Otherwise, the point closest to (lat, lon) is found. @raises: L{BadPointError} @param lat: latitude or point to search for @type lat: C{string} @param lon: longitude to search for @type lon: C{string} """ waypoint = None if lat.find('.') == -1: for pt in self.template_data['seg_dict'][self.options.id].waypoints: if pt.id == lat: waypoint = pt lat = pt.lat lon = pt.lon break else: raise BadPointError( "Matching point for '%s' not found!" % lat) else: dist = 100000.0 check_pt = Point(lat, lon) for pt in self.template_data['seg_dict'][self.options.id].waypoints: t_dist = check_pt.calculate_distance(pt) if t_dist < dist: waypoint = pt dist = t_dist return lat, lon, waypoint
def search_seg(sabx, seg_id, lat, lon): """ Search the indicated segment and find which waypoint is closest to the given (lat,lon) point. Print the result. """ search_pt = Point(lat, lon) shortest = 10000.0 for pt in sabx["seg_dict"][seg_id].waypoints: dist = search_pt.calculate_distance(pt) if dist < shortest: shortest = dist id = pt.id print "id= %s distant = %s" % (id, shortest)