source: subversion/applications/routing/pyroute/poi_base.py @ 5939

Last change on this file since 5939 was 5908, checked in by ojw, 12 years ago

test sorting

File size: 1.6 KB
Line 
1import geometry
2from base import pyrouteModule
3
4class poi:
5  def __init__(self,lat,lon):
6    self.lat = lat
7    self.lon = lon
8    self.title = 'Untitled at %1.3f, %1.3f' % (lat,lon)
9  def formatText(self):
10    return(self.title)
11  def distanceFrom(self,pos):
12    a = (pos['lat'], pos['lon'])
13    b = (self.lat,self.lon)
14    self.d = geometry.distance(a,b)
15    return(self.d)
16   
17  def __cmp__(self, other):
18    return cmp(self.d, other.d)
19   
20  def formatPos(self, ownPos = None):
21    if(ownPos and ownPos['valid']):
22      a = (ownPos['lat'], ownPos['lon'])
23      b = (self.lat,self.lon)
24      return("%1.2fkm at %03.1f" % \
25        (geometry.distance(a,b),
26        geometry.bearing(a,b)))
27    else:
28      return("%f,%f" % (self.lat,self.lon))
29
30class poiGroup:
31  def __init__(self,name):
32    self.items = []
33    self.name = name
34    self.sortpos = {'valid':False}
35   
36  def sort(self,pos):
37   
38    if(pos == self.sortpos):
39      return
40    self.sortpos = pos
41    print "Sorting"
42
43    if(pos['valid']):
44      for i in self.items:
45        i.d = i.distanceFrom(pos)
46
47    self.items.sort()
48    if(0):
49      for i in self.items:
50        print "%1.3f" % i.d
51
52   
53class poiModule(pyrouteModule):
54  def __init__(self, modules):
55    pyrouteModule.__init__(self, modules)
56    self.groups = []
57    self.draw = True
58
59  def sort(self, pos):
60    for g in self.groups:
61      g.sort(pos)
62     
63  def report(self):
64    for g in self.groups:
65      print "=== %s ===" % g.name
66      for i in g.items:
67        print "%1.3f, %1.3f = %s" % (i.lat, i.lon, i.title)
Note: See TracBrowser for help on using the repository browser.