/
bbox.py
77 lines (53 loc) · 2 KB
/
bbox.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from __builtin__ import True
class bound:
"""Bounding box of a layer"""
def __init__(self):
"""Bounds constructor
bbox = left,bottom,right,top
bbox = min Longitude , min Latitude , max Longitude , max Latitude
Latitude is a decimal number between -90.0 and 90.0.
Longitude is a decimal number between -180.0 and 180.0.
src: http://wiki.openstreetmap.org/wiki/Bounding_Box"""
self.left = -180.0
self.bottom = -90.0
self.right = 180.0
self.top = 90.0
self.inf = float("inf")
def setLeft(self, left):
"""Set the left extent of the bound
:param left: Minimum Longitude.
:type left: float"""
if self.isInf(left) == False:
self.left = left
else:
self.left = -180.0
def setBottom(self, bottom):
"""Set the bottom extent of the bound
:param bottom: Minimum Latitudes.
:type bottom: float"""
if self.isInf(bottom) == False:
self.bottom = bottom
else:
self.bottom = -90.0
def setRight(self, right):
"""Set the right extent of the bound
:param right: Maximum Longitude.
:type right: float"""
if self.isInf(right) == False:
self.right = right
else:
self.right = 180.0
def setTop(self, top):
"""Set the top extent of the bound
:param top: Maximum Latitude.
:type top: float """
if self.isInf(top) == False:
self.top = top
else:
self.top = 90.0
def isInf(self, val):
"""Broken layers sometimes return "infinity" for the bounds"""
if val == self.inf:
return True
else:
return False