1 |
# Copyright (c) 2001 by Intevation GmbH |
2 |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
4 |
# |
5 |
# This program is free software under the GPL (>=v2) |
6 |
# Read the file COPYING coming with Thuban for details. |
7 |
|
8 |
__version__ = "$Revision$" |
9 |
|
10 |
from types import StringTypes |
11 |
|
12 |
import Projection |
13 |
BaseProjection = Projection.Projection |
14 |
del Projection |
15 |
|
16 |
class Projection(BaseProjection): |
17 |
|
18 |
"""A proj4 projection object that remembers the parameters""" |
19 |
|
20 |
def __init__(self, params, name = "Unknown"): |
21 |
BaseProjection.__init__(self, params) |
22 |
self.params = params |
23 |
self.name = name |
24 |
|
25 |
def ForwardBBox(self, bbox): |
26 |
"""Return the bounding box of the corners of the bounding box bbox |
27 |
""" |
28 |
# This is not really the correct way to determine the bbox of a |
29 |
# projected shape, but for now it works well enough |
30 |
llx, lly, urx, ury = bbox |
31 |
xs = []; ys = [] |
32 |
x, y = self.Forward(llx, lly) |
33 |
xs.append(x); ys.append(y) |
34 |
x, y = self.Forward(llx, ury) |
35 |
xs.append(x); ys.append(y) |
36 |
x, y = self.Forward(urx, ury) |
37 |
xs.append(x); ys.append(y) |
38 |
x, y = self.Forward(urx, lly) |
39 |
xs.append(x); ys.append(y) |
40 |
return min(xs), min(ys), max(xs), max(ys) |
41 |
|
42 |
def GetName(self): |
43 |
return self.name |
44 |
|
45 |
def SetName(self, name): |
46 |
if isinstance(name, StringTypes): |
47 |
self.name = name |
48 |
|
49 |
def GetParameter(self, param): |
50 |
|
51 |
for pair in self.params: |
52 |
p, v = pair.split("=") |
53 |
if p == param: |
54 |
return v |
55 |
|
56 |
return "" |
57 |
|
58 |
def GetAllParameters(self): |
59 |
return self.params |
60 |
|
61 |
def __repr__(self): |
62 |
return self.name + ": " + repr(self.params) |
63 |
|
64 |
class ProjFile: |
65 |
|
66 |
def __init__(self, filename): |
67 |
self.projs = {} |
68 |
|
69 |
self.SetFileName(filename) |
70 |
|
71 |
def Add(self, proj): |
72 |
self.projs[proj] = 0 |
73 |
|
74 |
def Remove(self, proj): |
75 |
if self.projs.has_key(proj): |
76 |
del self.projs[proj] |
77 |
|
78 |
def GetFileName(self): |
79 |
return self.filename |
80 |
|
81 |
def SetFileName(self, filename): |
82 |
self.filename = filename |
83 |
|
84 |
def GetProjections(self): |
85 |
return self.projs.keys() |