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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6 by bh, Tue Aug 28 15:41:52 2001 UTC revision 738 by jonathan, Fri Apr 25 09:13:36 2003 UTC
# Line 7  Line 7 
7    
8  __version__ = "$Revision$"  __version__ = "$Revision$"
9    
10    from types import StringTypes
11    
12  import Projection  import Projection
13  BaseProjection = Projection.Projection  BaseProjection = Projection.Projection
14  del Projection  del Projection
# Line 15  class Projection(BaseProjection): Line 17  class Projection(BaseProjection):
17    
18      """A proj4 projection object that remembers the parameters"""      """A proj4 projection object that remembers the parameters"""
19    
20      def __init__(self, params):      def __init__(self, params, name = "Unknown"):
21          BaseProjection.__init__(self, params)          BaseProjection.__init__(self, params)
22          self.params = params          self.params = params
23            self.name = name
24    
25      def ForwardBBox(self, bbox):      def ForwardBBox(self, bbox):
26          """Return the bounding box of the corners of the bounding box bbox          """Return the bounding box of the corners of the bounding box bbox
# Line 35  class Projection(BaseProjection): Line 38  class Projection(BaseProjection):
38          x, y = self.Forward(urx, lly)          x, y = self.Forward(urx, lly)
39          xs.append(x); ys.append(y)          xs.append(x); ys.append(y)
40          return min(xs), min(ys), max(xs), max(ys)          return min(xs), min(ys), max(xs), max(ys)
41    
42        def GetName(self):
43            """Return the name of the projection."""
44            return self.name
45    
46        def SetName(self, name):
47            """Set the name of the projection."""
48            if isinstance(name, StringTypes):
49                self.name = name
50    
51        def GetParameter(self, param):
52            """Return the projection value for the given parameter.
53    
54            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            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            """Return list of 'parameter=value' strings"""
68            return self.params
69    
70        def __repr__(self):
71            return self.name + ": " + repr(self.params)
72    
73    class ProjFile:
74    
75        def __init__(self, filename):
76            """Intialize the ProjFile.
77    
78            filename -- name of the file that this ProjFile represents.
79            """
80    
81            self.__projs = []
82    
83            self.SetFilename(filename)
84        
85        def Add(self, proj):
86            """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    
91            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        def Remove(self, proj):
101            """Remove the objection proj from the projection file.
102    
103            Raises a ValueError is proj is not found.
104            """
105    
106            self.__projs.remove(proj)
107    
108        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        def GetProjections(self):
120            """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    

Legend:
Removed from v.6  
changed lines
  Added in v.738

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26