forked from perliedman/shadow-mapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.py
More file actions
38 lines (31 loc) · 1.07 KB
/
map.py
File metadata and controls
38 lines (31 loc) · 1.07 KB
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
from __future__ import division
from past.utils import old_div
import pickle
class Map():
def __init__(self, lat, lng, resolution, size, proj):
self.lat = lat
self.lng = lng
self.resolution = resolution
self.size = size
self.psize = size * resolution
self.proj = proj
cx, cy = proj(lng, lat)
self.bounds = (
cx - old_div(self.psize, 2),
cy - old_div(self.psize, 2),
cx + old_div(self.psize, 2),
cy + old_div(self.psize, 2),
)
w, s = proj(self.bounds[0], self.bounds[1], inverse=True)
e, n = proj(self.bounds[2], self.bounds[3], inverse=True)
self.ll_bounds = (s, w, n, e)
def _latLngToIndex(self, lat, lng):
x, y = self.proj(lng, lat)
return (
old_div((x - self.bounds[0]), self.psize) * self.size,
old_div((y - self.bounds[1]), self.psize) * self.size)
def save(self, f):
pickle.dump(self, f, pickle.HIGHEST_PROTOCOL)
@staticmethod
def load(f):
return pickle.load(f)