22 |
|
|
23 |
"""A proj4 projection object that remembers the parameters""" |
"""A proj4 projection object that remembers the parameters""" |
24 |
|
|
25 |
def __init__(self, params, name = None): |
def __init__(self, params, name = None, epsg = None): |
26 |
"""Initialize the Projection with a list of |
"""Initialize the Projection |
27 |
'parameter=value' strings and an optional name. If 'name' is |
|
28 |
None, the name will be set to 'Unknown' in the local language. |
Parameters: |
29 |
""" |
|
30 |
|
params -- a list of 'parameter=value' strings |
31 |
|
|
32 |
|
name -- (optional) The name of the projectin. If None or omitted |
33 |
|
it defaults to 'Unknown' in the local language. |
34 |
|
|
35 |
|
epsg -- (optional) The EPSG code as a string. |
36 |
|
""" |
37 |
BaseProjection.__init__(self, params) |
BaseProjection.__init__(self, params) |
38 |
|
|
39 |
if name is None: |
if name is None: |
41 |
elif isinstance(name, StringTypes): |
elif isinstance(name, StringTypes): |
42 |
self.name = name |
self.name = name |
43 |
|
|
44 |
|
self.epsg = epsg |
45 |
self.params = params |
self.params = params |
46 |
|
|
47 |
def ForwardBBox(self, bbox): |
def ForwardBBox(self, bbox): |
66 |
"""Return the name of the projection.""" |
"""Return the name of the projection.""" |
67 |
return self.name |
return self.name |
68 |
|
|
69 |
|
def Label(self): |
70 |
|
if self.epsg: |
71 |
|
return "EPSG % 5s %s" % (self.epsg, self.name) |
72 |
|
return self.name |
73 |
|
|
74 |
|
def EPSGCode(self): |
75 |
|
"""Return the EPSG code as a string or None if there is none""" |
76 |
|
return self.epsg |
77 |
|
|
78 |
def GetParameter(self, param): |
def GetParameter(self, param): |
79 |
"""Return the projection value for the given parameter. |
"""Return the projection value for the given parameter. |
80 |
|
|
109 |
def __repr__(self): |
def __repr__(self): |
110 |
return self.name + ": " + repr(self.params) |
return self.name + ": " + repr(self.params) |
111 |
|
|
112 |
|
|
113 |
class ProjFile: |
class ProjFile: |
114 |
|
|
115 |
def __init__(self, filename): |
def __init__(self, filename): |
123 |
self.SetFilename(filename) |
self.SetFilename(filename) |
124 |
|
|
125 |
def Add(self, proj): |
def Add(self, proj): |
126 |
"""Add the given projection to the end of the file. If 'proj' |
"""Add the projection to the end of the file.""" |
127 |
already exists, it is replaced in the same location as the |
self.__projs.append(proj) |
|
original projection. |
|
|
""" |
|
|
|
|
|
try: |
|
|
# |
|
|
# see if the projection already exists. |
|
|
# this only works if Projection doesn't override __eq__ |
|
|
# |
|
|
self.__projs[self.__projs.index(proj)] = proj |
|
|
except ValueError: |
|
|
self.__projs.append(proj) |
|
128 |
|
|
129 |
def Remove(self, proj): |
def Remove(self, proj): |
130 |
"""Remove the object proj from the projection file. |
"""Remove the object proj from the projection file. |