7 |
|
|
8 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
9 |
|
|
|
from Thuban import _ |
|
|
|
|
10 |
from types import StringTypes |
from types import StringTypes |
11 |
|
|
12 |
|
from Thuban import _ |
13 |
|
from Thuban.Lib.connector import Publisher |
14 |
|
|
15 |
import Projection |
import Projection |
16 |
BaseProjection = Projection.Projection |
BaseProjection = Projection.Projection |
17 |
del Projection |
del Projection |
18 |
|
|
19 |
|
from messages import PROJECTION_ADDED, PROJECTION_REPLACED, PROJECTION_REMOVED |
20 |
|
|
21 |
PROJ_UNITS_METERS = 1 |
PROJ_UNITS_METERS = 1 |
22 |
PROJ_UNITS_DEGREES = 2 |
PROJ_UNITS_DEGREES = 2 |
23 |
|
|
47 |
self.epsg = epsg |
self.epsg = epsg |
48 |
self.params = params |
self.params = params |
49 |
|
|
50 |
def ForwardBBox(self, bbox): |
def _transform_bbox(self, trafo, bbox): |
|
"""Return the bounding box of the corners of the bounding box bbox |
|
|
""" |
|
51 |
# This is not really the correct way to determine the bbox of a |
# This is not really the correct way to determine the bbox of a |
52 |
# projected shape, but for now it works well enough |
# projected bbox, but for now it works well enough |
53 |
llx, lly, urx, ury = bbox |
llx, lly, urx, ury = bbox |
54 |
xs = []; ys = [] |
xs = []; ys = [] |
55 |
x, y = self.Forward(llx, lly) |
for x, y in ((llx, lly), (llx, ury), (urx, lly), (urx, ury)): |
56 |
xs.append(x); ys.append(y) |
x, y = trafo(x, y) |
57 |
x, y = self.Forward(llx, ury) |
xs.append(x); ys.append(y) |
|
xs.append(x); ys.append(y) |
|
|
x, y = self.Forward(urx, ury) |
|
|
xs.append(x); ys.append(y) |
|
|
x, y = self.Forward(urx, lly) |
|
|
xs.append(x); ys.append(y) |
|
|
|
|
58 |
return min(xs), min(ys), max(xs), max(ys) |
return min(xs), min(ys), max(xs), max(ys) |
59 |
|
|
60 |
|
def ForwardBBox(self, bbox): |
61 |
|
"""Return the bounding box of the corners of the bounding box bbox |
62 |
|
""" |
63 |
|
return self._transform_bbox(self.Forward, bbox) |
64 |
|
|
65 |
|
def InverseBBox(self, bbox): |
66 |
|
return self._transform_bbox(self.Inverse, bbox) |
67 |
|
|
68 |
def GetName(self): |
def GetName(self): |
69 |
"""Return the name of the projection.""" |
"""Return the name of the projection.""" |
70 |
return self.name |
return self.name |
104 |
return self.params |
return self.params |
105 |
|
|
106 |
def GetProjectedUnits(self): |
def GetProjectedUnits(self): |
107 |
if self.GetParameter("proj") == "latlong": |
if self.GetParameter("proj") in [ 'latlong', 'longlat' ]: |
108 |
return PROJ_UNITS_DEGREES |
return PROJ_UNITS_DEGREES |
109 |
else: |
else: |
110 |
return PROJ_UNITS_METERS |
return PROJ_UNITS_METERS |
113 |
return self.name + ": " + repr(self.params) |
return self.name + ": " + repr(self.params) |
114 |
|
|
115 |
|
|
116 |
class ProjFile: |
class ProjFile(Publisher): |
117 |
|
|
118 |
def __init__(self, filename): |
def __init__(self, filename): |
119 |
"""Intialize the ProjFile. |
"""Intialize the ProjFile. |
124 |
self.__projs = [] |
self.__projs = [] |
125 |
|
|
126 |
self.SetFilename(filename) |
self.SetFilename(filename) |
127 |
|
|
128 |
def Add(self, proj): |
def Add(self, proj): |
129 |
"""Add the projection to the end of the file.""" |
"""Add the projection to the end of the file.""" |
130 |
self.__projs.append(proj) |
self.__projs.append(proj) |
131 |
|
self.issue(PROJECTION_ADDED, proj) |
132 |
|
|
133 |
def Remove(self, proj): |
def Remove(self, proj): |
134 |
"""Remove the object proj from the projection file. |
"""Remove the object proj from the projection file. |
135 |
|
|
136 |
Raises a ValueError is proj is not found. |
Raises a ValueError is proj is not found. |
137 |
""" |
""" |
|
|
|
138 |
self.__projs.remove(proj) |
self.__projs.remove(proj) |
139 |
|
self.issue(PROJECTION_REMOVED, proj) |
140 |
|
|
141 |
def Replace(self, oldproj, newproj): |
def Replace(self, oldproj, newproj): |
142 |
"""Replace the object 'oldproj' with 'newproj'. |
"""Replace the object 'oldproj' with 'newproj'. |
143 |
|
|
144 |
Raises ValueError if oldproj is not in the file. |
Raises ValueError if oldproj is not in the file. |
145 |
""" |
""" |
|
|
|
|
# |
|
|
# see if the projection already exists. |
|
|
# this only works if Projection doesn't override __eq__ |
|
|
# |
|
146 |
self.__projs[self.__projs.index(oldproj)] = newproj |
self.__projs[self.__projs.index(oldproj)] = newproj |
147 |
|
self.issue(PROJECTION_REPLACED, oldproj, newproj) |
148 |
|
|
149 |
def GetFilename(self): |
def GetFilename(self): |
150 |
"""Return the filename where the ProjFile was read or will be |
"""Return the filename where the ProjFile was read or will be |