Package sabx10 :: Package osm :: Module zoom
[hide private]
[frames] | no frames]

Source Code for Module sabx10.osm.zoom

  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  Handle zoom levels for stops, pois, and turns.  It turns out that all three are 
 23  sufficiently similar that they can be processed generically. 
 24  """ 
 25   
26 -def find_close_item(item_list, check_item, dist):
27 """ 28 Find the first item in item_list closer to the check_item than dist. 29 30 @param item_list: C{list} of L{Point} items to check 31 @type item_list: C{list} of L{Point} 32 @param check_item: L{Point} to check against 33 @type check_item: L{Point} 34 @param dist: threshhold distance to check for 35 @type dist: C{float} 36 """ 37 for item in item_list: 38 if check_item.calculate_distance(item) <= dist: 39 return item 40 41 return None
42
43 -class ZoomItem(object):
44 """ 45 Item referencing several non-zoomed items. 46 47 @ivar lat: latitude 48 @type lat: C{float} 49 @ivar lon: longitude 50 @type lon: C{float} 51 @ivar node_id: id of this item 52 @type node_id: C{int} 53 @ivar name: name of this item 54 @type name: C{string} 55 """
56 - def __init__(self, lat, lon, node_id, name):
57 """ 58 Save the passed-in values 59 60 @param lat: latitude 61 @type lat: C{float} 62 @param lon: longitude 63 @type lon: C{float} 64 @param node_id: id 65 @type node_id: C{int} 66 @param name: name 67 @type name: C{string} 68 """ 69 self.lat = lat 70 self.lon = lon 71 self.node_id = node_id 72 self.name = name
73
74 -def get_zoom_items(items, dist, node_id):
75 """ 76 Generate a "compacted" list of items based on a full item list. This finds 77 all items that are close to eachother, within a distance of "dist", and 78 creates one item that references all of the close items. This is good when 79 a map would show a bunch of hard-to-read overlapping items at a spot, but 80 will now show one single item instead. 81 82 @param items: list of items to compact 83 @type items: C{list} of L{Point} items 84 @param dist: threshold distance between items 85 @type dist: C{float} 86 @param node_id: L{NodeId} object to get ids for zoomed items 87 @type node_id: L{NodeId} 88 """ 89 zoomed_items = [] 90 91 # process segs 92 for index, item in enumerate(items): 93 old_item = find_close_item(zoomed_items, item, dist) 94 if old_item is not None: 95 old_item.name = "%s,%s" % (old_item.name, index+1) 96 else: 97 new_item = ZoomItem(item.lat, item.lon, node_id.next(), index+1) 98 zoomed_items.append(new_item) 99 100 return zoomed_items
101