source: subversion/applications/routing/pyroute/projection.py @ 5502

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

forgot to add projection code

File size: 1.4 KB
Line 
1
2class Projection:
3  def __init__(self):
4    self.xyValid = 0
5    self.llValid = 0
6  def isValid(self):
7    return(self.xyValid and self.llValid)
8  def setView(self,x,y,w,h):
9    self.w = w / 2
10    self.h = h / 2
11    self.xc = x + self.w
12    self.yc = y + self.h
13    self.xyValid = 1
14  def recentre(self,lat,lon,scale):
15    self.lat = lat
16    self.lon = lon
17    self.scale = scale  # TODO: scale and scaleCosLat
18    self.findEdges()
19    self.llValid = 1
20  def findEdges(self):
21    """(S,W,E,N) are derived from (lat,lon,scale)"""
22    self.S = self.lat - self.scale
23    self.N = self.lat + self.scale
24    self.W = self.lon - self.scale
25    self.E = self.lon + self.scale
26  def nudge(self,dx,dy,scale):
27    self.lat = self.lat + dy * scale * self.scale
28    self.lon = self.lon + dx * scale * self.scale
29    self.findEdges()
30  def ll2xy(self,lat,lon):
31    px = (lon - self.lon) / self.scale
32    py = (lat - self.lat) / self.scale
33    x = self.xc + self.w * px
34    y = self.yc - self.h * py
35    return(x,y)
36  def xy2ll(self,x,y):
37    px = (x - self.xc) / self.w
38    py = (y - self.yc) / self.h
39    lon = self.lon + px * self.scale
40    lat = self.lat - py * self.scale
41    return(lat,lon)
42  def onscreen(self,x,y):
43    return(x >= 0 and x < 2 * self.w and y >= 0 and y < 2 * self.h)
44  def relXY(self,x,y):
45    return(x/(2*self.w), y/(2*self.h))
46   
Note: See TracBrowser for help on using the repository browser.