7 |
|
|
8 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
9 |
|
|
10 |
|
from Thuban import _ |
11 |
|
|
12 |
|
from types import StringTypes |
13 |
|
|
14 |
import Projection |
import Projection |
15 |
BaseProjection = Projection.Projection |
BaseProjection = Projection.Projection |
16 |
del Projection |
del Projection |
19 |
|
|
20 |
"""A proj4 projection object that remembers the parameters""" |
"""A proj4 projection object that remembers the parameters""" |
21 |
|
|
22 |
def __init__(self, params, name = "Unknown"): |
def __init__(self, params, name = None): |
23 |
|
"""Initialize the Projection with a list of |
24 |
|
'parameter=value' strings and an optional name. If 'name' is |
25 |
|
None, the name will be set to 'Unknown' in the local language. |
26 |
|
""" |
27 |
|
|
28 |
BaseProjection.__init__(self, params) |
BaseProjection.__init__(self, params) |
29 |
|
|
30 |
|
if name is None: |
31 |
|
name = _("Unknown") |
32 |
|
|
33 |
self.params = params |
self.params = params |
34 |
self.name = name |
self.name = name |
35 |
|
|
51 |
return min(xs), min(ys), max(xs), max(ys) |
return min(xs), min(ys), max(xs), max(ys) |
52 |
|
|
53 |
def GetName(self): |
def GetName(self): |
54 |
|
"""Return the name of the projection.""" |
55 |
return self.name |
return self.name |
56 |
|
|
57 |
def GetParameters(self): |
def SetName(self, name): |
58 |
|
"""Set the name of the projection.""" |
59 |
|
if isinstance(name, StringTypes): |
60 |
|
self.name = name |
61 |
|
|
62 |
|
def GetParameter(self, param): |
63 |
|
"""Return the projection value for the given parameter. |
64 |
|
|
65 |
|
If 'param' exists as a valid parameter then the returned |
66 |
|
value is a string with that value. If the parameter doesn't |
67 |
|
exist an empty string is returned. |
68 |
|
""" |
69 |
|
|
70 |
|
for pair in self.params: |
71 |
|
p, v = pair.split("=") |
72 |
|
if p == param: |
73 |
|
return v |
74 |
|
|
75 |
|
return "" |
76 |
|
|
77 |
|
def GetAllParameters(self): |
78 |
|
"""Return list of 'parameter=value' strings""" |
79 |
return self.params |
return self.params |
80 |
|
|
81 |
def __repr__(self): |
def __repr__(self): |
82 |
return repr(self.params) |
return self.name + ": " + repr(self.params) |
83 |
|
|
84 |
class ProjFile: |
class ProjFile: |
85 |
|
|
86 |
def __init__(self, filename): |
def __init__(self, filename): |
87 |
self.projs = [] |
"""Intialize the ProjFile. |
88 |
|
|
89 |
|
filename -- name of the file that this ProjFile represents. |
90 |
|
""" |
91 |
|
|
92 |
|
self.__projs = [] |
93 |
|
|
94 |
self.SetFileName(filename) |
self.SetFilename(filename) |
95 |
|
|
96 |
def Add(self, proj): |
def Add(self, proj): |
97 |
self.projs.append(proj) |
"""Add the given projection to the end of the file. If 'proj' |
98 |
|
already exists, it is replaced in the same location as the |
99 |
|
original projection. |
100 |
|
""" |
101 |
|
|
102 |
|
try: |
103 |
|
# |
104 |
|
# see if the projection already exists. |
105 |
|
# this only works if Projection doesn't override __eq__ |
106 |
|
# |
107 |
|
self.__projs[self.__projs.index(proj)] = proj |
108 |
|
except ValueError: |
109 |
|
self.__projs.append(proj) |
110 |
|
|
111 |
|
def Remove(self, proj): |
112 |
|
"""Remove the objection proj from the projection file. |
113 |
|
|
114 |
|
Raises a ValueError is proj is not found. |
115 |
|
""" |
116 |
|
|
117 |
|
self.__projs.remove(proj) |
118 |
|
|
119 |
def GetFileName(self): |
def GetFilename(self): |
120 |
return self.filename |
"""Return the filename where the ProjFile was read or will be |
121 |
|
written to. |
122 |
|
""" |
123 |
|
|
124 |
|
return self.__filename |
125 |
|
|
126 |
def SetFileName(self, filename): |
def SetFilename(self, filename): |
127 |
self.filename = filename |
"""Set the filename where the ProjFile will be written to.""" |
128 |
|
self.__filename = filename |
129 |
|
|
130 |
def GetProjections(self): |
def GetProjections(self): |
131 |
return self.projs |
"""Return a list of the projections in the order they were read |
132 |
|
from the file or will be written. |
133 |
|
|
134 |
|
This is not a deep copy list, so any modifications made to the |
135 |
|
Projection objects will be written to the file. |
136 |
|
""" |
137 |
|
|
138 |
|
return self.__projs |
139 |
|
|