/[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 758 - (hide annotations)
Tue Apr 29 09:01:12 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: 4201 byte(s)
(Projection): Removed Set*() methods to make
        Projection an immutable item. Fixes RTbug #1825.
(Projection.__init__): Initialize instance variables here.
(ProjFile.Replace): New. Replace the given projection object with
        the new projection object. This solves the problem of needing the
        mutator Projection.SetProjection() in the ProjFrame class and
        allows a projection to change parameters without changing its
        location in the file.

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 745 from Thuban import _
11    
12 jonathan 726 from types import StringTypes
13    
14 bh 6 import Projection
15     BaseProjection = Projection.Projection
16     del Projection
17    
18     class Projection(BaseProjection):
19    
20     """A proj4 projection object that remembers the parameters"""
21    
22 jonathan 745 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 bh 6 BaseProjection.__init__(self, params)
29 jonathan 745
30 jonathan 758 if name is None:
31     self.name = _("Unknown")
32     elif isinstance(name, StringTypes):
33     self.name = name
34 jonathan 745
35 jonathan 758 self.params = params
36    
37 bh 6 def ForwardBBox(self, bbox):
38     """Return the bounding box of the corners of the bounding box bbox
39     """
40     # This is not really the correct way to determine the bbox of a
41     # projected shape, but for now it works well enough
42     llx, lly, urx, ury = bbox
43     xs = []; ys = []
44     x, y = self.Forward(llx, lly)
45     xs.append(x); ys.append(y)
46     x, y = self.Forward(llx, ury)
47     xs.append(x); ys.append(y)
48     x, y = self.Forward(urx, ury)
49     xs.append(x); ys.append(y)
50     x, y = self.Forward(urx, lly)
51     xs.append(x); ys.append(y)
52 jonathan 758
53 bh 6 return min(xs), min(ys), max(xs), max(ys)
54 jonathan 695
55     def GetName(self):
56 jonathan 738 """Return the name of the projection."""
57 jonathan 695 return self.name
58    
59 jonathan 708 def GetParameter(self, param):
60 jonathan 738 """Return the projection value for the given parameter.
61 jonathan 708
62 jonathan 738 If 'param' exists as a valid parameter then the returned
63     value is a string with that value. If the parameter doesn't
64     exist an empty string is returned.
65     """
66    
67 jonathan 708 for pair in self.params:
68     p, v = pair.split("=")
69     if p == param:
70     return v
71    
72     return ""
73    
74     def GetAllParameters(self):
75 jonathan 738 """Return list of 'parameter=value' strings"""
76 jonathan 695 return self.params
77    
78     def __repr__(self):
79 jonathan 726 return self.name + ": " + repr(self.params)
80 jonathan 695
81     class ProjFile:
82    
83     def __init__(self, filename):
84 jonathan 738 """Intialize the ProjFile.
85 jonathan 695
86 jonathan 738 filename -- name of the file that this ProjFile represents.
87     """
88    
89     self.__projs = []
90    
91     self.SetFilename(filename)
92 jonathan 695
93     def Add(self, proj):
94 jonathan 738 """Add the given projection to the end of the file. If 'proj'
95     already exists, it is replaced in the same location as the
96     original projection.
97     """
98 jonathan 695
99 jonathan 738 try:
100     #
101     # see if the projection already exists.
102     # this only works if Projection doesn't override __eq__
103     #
104     self.__projs[self.__projs.index(proj)] = proj
105     except ValueError:
106     self.__projs.append(proj)
107    
108 jonathan 726 def Remove(self, proj):
109 jonathan 758 """Remove the object proj from the projection file.
110 jonathan 726
111 jonathan 738 Raises a ValueError is proj is not found.
112     """
113 jonathan 695
114 jonathan 738 self.__projs.remove(proj)
115 jonathan 695
116 jonathan 758 def Replace(self, oldproj, newproj):
117     """Replace the object 'oldproj' with 'newproj'.
118    
119     Raises ValueError if oldproj is not in the file.
120     """
121    
122     #
123     # see if the projection already exists.
124     # this only works if Projection doesn't override __eq__
125     #
126     self.__projs[self.__projs.index(oldproj)] = newproj
127    
128 jonathan 738 def GetFilename(self):
129     """Return the filename where the ProjFile was read or will be
130     written to.
131     """
132    
133     return self.__filename
134    
135     def SetFilename(self, filename):
136     """Set the filename where the ProjFile will be written to."""
137     self.__filename = filename
138    
139 jonathan 695 def GetProjections(self):
140 jonathan 738 """Return a list of the projections in the order they were read
141     from the file or will be written.
142    
143     This is not a deep copy list, so any modifications made to the
144     Projection objects will be written to the file.
145     """
146    
147     return self.__projs
148    

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26