summaryrefslogtreecommitdiff
path: root/layers.py
blob: 38aeba4332f1eea1b5c626ee4cc4453065527eb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from PIL import Image
from latLng import latLng

class layer:
	"""a generic GPS image layer"""
	tl=latLng()
	br=latLng()
	pixel=latLng()
	def __init__(self,file,ll1,ll2):
		try:
			self.image=Image.open(file)
		except:
			print "gps layer: failed to open", file
		try:
			self.tl.parse(ll1)
			self.br.parse(ll2)
			self.pixsize=latLng(abs(self.tl.lat-self.br.lat)/self.image.size[1],abs(self.tl.lng-self.br.lng)/self.image.size[0])
		except:
			print "gps layer: failed to parse", file
	def findpixel(self,pos):
		return latLng(int((pos.lng-self.tl.lng)/self.pixsize.lng),int((pos.lat-self.br.lat)/self.pixsize.lat))
	def checkcoord(self,pos):
		p=self.findpixel(pos)
		if p!=self.pixel:
			self.pixel=p
			return self.setcoord(p)
		else:
			return None
	def setcoord(self,pos):
		return str(1.0)
		
class trigger():
	"""a generic trigger - 
	id can be anything - 
	i.e. a string or an integer"""
	def __init__(self,id,command,param):
		self.id=id
		self.command=(command,param)
	def check(self,id):
		if id==self.id:
			return command
		else:
			return None
		
class indexlayer(layer):
	triggers=[]
	def setcoord(self,pos):
		return str(1)