/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/proj.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Thuban/Model/proj.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 738 - (hide annotations)
Fri Apr 25 09:13:36 2003 UTC (21 years, 10 months ago) by jonathan
Original Path: trunk/thuban/Thuban/Model/proj.py
File MIME type: text/x-python
File size: 3638 byte(s)
(ProjFile): Document the class. Move
        back to using a list because the order of the projections in
        the file is important to maintain. Fixes RTbug #1817.

1 bh 6 # 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 jonathan 726 from types import StringTypes
11    
12 bh 6 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 jonathan 695 def __init__(self, params, name = "Unknown"):
21 bh 6 BaseProjection.__init__(self, params)
22     self.params = params
23 jonathan 695 self.name = name
24 bh 6
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 jonathan 695
42     def GetName(self):
43 jonathan 738 """Return the name of the projection."""
44 jonathan 695 return self.name
45    
46 jonathan 726 def SetName(self, name):
47 jonathan 738 """Set the name of the projection."""
48 jonathan 726 if isinstance(name, StringTypes):
49     self.name = name
50    
51 jonathan 708 def GetParameter(self, param):
52 jonathan 738 """Return the projection value for the given parameter.
53 jonathan 708
54 jonathan 738 If 'param' exists as a valid parameter then the returned
55     value is a string with that value. If the parameter doesn't
56     exist an empty string is returned.
57     """
58    
59 jonathan 708 for pair in self.params:
60     p, v = pair.split("=")
61     if p == param:
62     return v
63    
64     return ""
65    
66     def GetAllParameters(self):
67 jonathan 738 """Return list of 'parameter=value' strings"""
68 jonathan 695 return self.params
69    
70     def __repr__(self):
71 jonathan 726 return self.name + ": " + repr(self.params)
72 jonathan 695
73     class ProjFile:
74    
75     def __init__(self, filename):
76 jonathan 738 """Intialize the ProjFile.
77 jonathan 695
78 jonathan 738 filename -- name of the file that this ProjFile represents.
79     """
80    
81     self.__projs = []
82    
83     self.SetFilename(filename)
84 jonathan 695
85     def Add(self, proj):
86 jonathan 738 """Add the given projection to the end of the file. If 'proj'
87     already exists, it is replaced in the same location as the
88     original projection.
89     """
90 jonathan 695
91 jonathan 738 try:
92     #
93     # see if the projection already exists.
94     # this only works if Projection doesn't override __eq__
95     #
96     self.__projs[self.__projs.index(proj)] = proj
97     except ValueError:
98     self.__projs.append(proj)
99    
100 jonathan 726 def Remove(self, proj):
101 jonathan 738 """Remove the objection proj from the projection file.
102 jonathan 726
103 jonathan 738 Raises a ValueError is proj is not found.
104     """
105 jonathan 695
106 jonathan 738 self.__projs.remove(proj)
107 jonathan 695
108 jonathan 738 def GetFilename(self):
109     """Return the filename where the ProjFile was read or will be
110     written to.
111     """
112    
113     return self.__filename
114    
115     def SetFilename(self, filename):
116     """Set the filename where the ProjFile will be written to."""
117     self.__filename = filename
118    
119 jonathan 695 def GetProjections(self):
120 jonathan 738 """Return a list of the projections in the order they were read
121     from the file or will be written.
122    
123     This is not a deep copy list, so any modifications made to the
124     Projection objects will be written to the file.
125     """
126    
127     return self.__projs
128    

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26