source: subversion/applications/routing/pyroute-dev/poi_base.py @ 18447

Last change on this file since 18447 was 18447, checked in by buerste, 10 years ago

-modifying file intro

File size: 2.3 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5"""
6
7__version__ = "$Rev$"
8__license__ = """This program is free software: you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation, either version 3 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program. If not, see <http://www.gnu.org/licenses/>."""
20_debug = 0
21
22
23import geometry
24from base import pyrouteModule
25import listable
26
27class poi:
28  def __init__(self,lat,lon):
29    self.lat = lat
30    self.lon = lon
31    self.title = 'Untitled at %1.3f, %1.3f' % (lat,lon)
32  def formatText(self):
33    return(self.title)
34  def distanceFrom(self,pos):
35    a = (pos['lat'], pos['lon'])
36    b = (self.lat,self.lon)
37    self.d = geometry.distance(a,b)
38    return(self.d)
39   
40  def __cmp__(self, other):
41    return cmp(self.d, other.d)
42
43class poiGroup(listable.listable):
44  def __init__(self,name):
45    self.items = []
46    self.name = name
47    self.sortpos = {'valid':False}
48   
49  # Functions to implement the listable interface
50  def numItems(self):
51    return(len(self.items))
52  def getItemText(self,n):
53    return(self.items[n].title)
54  def isLocation(self,n):
55    return(True)
56  def getItemLatLon(self,n):
57    item = self.items[n]
58    return(item.lat,item.lon)
59
60  def sort(self,pos):
61   
62    if(pos == self.sortpos):
63      return
64    self.sortpos = pos
65    print "Sorting"
66
67    if(pos['valid']):
68      for i in self.items:
69        i.d = i.distanceFrom(pos)
70
71    self.items.sort()
72    if(0):
73      for i in self.items:
74        print "%1.3f" % i.d
75
76   
77class poiModule(pyrouteModule):
78  def __init__(self, modules):
79    pyrouteModule.__init__(self, modules)
80    self.groups = []
81    self.draw = True
82
83  def sort(self, pos):
84    for g in self.groups:
85      g.sort(pos)
86     
87  def report(self):
88    for g in self.groups:
89      print "=== %s ===" % g.name
90      for i in g.items:
91        print "%1.3f, %1.3f = %s" % (i.lat, i.lon, i.title)
Note: See TracBrowser for help on using the repository browser.