/[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 1802 by bh, Thu Oct 9 15:18:35 2003 UTC revision 1824 by bh, Tue Oct 14 15:21:03 2003 UTC
# Line 7  Line 7 
7    
8  __version__ = "$Revision$"  __version__ = "$Revision$"
9    
 from Thuban import _  
   
10  from types import StringTypes  from types import StringTypes
11    
12    from Thuban import _
13    from Thuban.Lib.connector import Publisher
14    
15  import Projection  import Projection
16  BaseProjection = Projection.Projection  BaseProjection = Projection.Projection
17  del Projection  del Projection
18    
19    from messages import PROJECTION_ADDED, PROJECTION_REPLACED, PROJECTION_REMOVED
20    
21  PROJ_UNITS_METERS  = 1  PROJ_UNITS_METERS  = 1
22  PROJ_UNITS_DEGREES = 2  PROJ_UNITS_DEGREES = 2
23    
# Line 22  class Projection(BaseProjection): Line 25  class Projection(BaseProjection):
25    
26      """A proj4 projection object that remembers the parameters"""      """A proj4 projection object that remembers the parameters"""
27    
28      def __init__(self, params, name = None):      def __init__(self, params, name = None, epsg = None):
29          """Initialize the Projection with a list of          """Initialize the Projection
30          'parameter=value' strings and an optional name. If 'name' is  
31          None, the name will be set to 'Unknown' in the local language.          Parameters:
32          """  
33            params -- a list of 'parameter=value' strings
34    
35            name -- (optional) The name of the projectin. If None or omitted
36                    it defaults to 'Unknown' in the local language.
37    
38            epsg -- (optional) The EPSG code as a string.
39            """
40          BaseProjection.__init__(self, params)          BaseProjection.__init__(self, params)
41    
42          if name is None:          if name is None:
# Line 35  class Projection(BaseProjection): Line 44  class Projection(BaseProjection):
44          elif isinstance(name, StringTypes):          elif isinstance(name, StringTypes):
45              self.name = name              self.name = name
46    
47            self.epsg = epsg
48          self.params = params          self.params = params
49    
50      def ForwardBBox(self, bbox):      def ForwardBBox(self, bbox):
# Line 59  class Projection(BaseProjection): Line 69  class Projection(BaseProjection):
69          """Return the name of the projection."""          """Return the name of the projection."""
70          return self.name          return self.name
71    
72        def Label(self):
73            if self.epsg:
74                return "EPSG % 5s %s" % (self.epsg, self.name)
75            return self.name
76    
77        def EPSGCode(self):
78            """Return the EPSG code as a string or None if there is none"""
79            return self.epsg
80    
81      def GetParameter(self, param):      def GetParameter(self, param):
82          """Return the projection value for the given parameter.          """Return the projection value for the given parameter.
83    
# Line 93  class Projection(BaseProjection): Line 112  class Projection(BaseProjection):
112      def __repr__(self):      def __repr__(self):
113          return self.name + ": " + repr(self.params)          return self.name + ": " + repr(self.params)
114    
115  class ProjFile:  
116    class ProjFile(Publisher):
117    
118      def __init__(self, filename):      def __init__(self, filename):
119          """Intialize the ProjFile.          """Intialize the ProjFile.
# Line 104  class ProjFile: Line 124  class ProjFile:
124          self.__projs = []          self.__projs = []
125    
126          self.SetFilename(filename)          self.SetFilename(filename)
127        
128      def Add(self, proj):      def Add(self, proj):
129          """Add the projection to the end of the file."""          """Add the projection to the end of the file."""
130          self.__projs.append(proj)          self.__projs.append(proj)
131            self.issue(PROJECTION_ADDED, proj)
132    
133      def Remove(self, proj):      def Remove(self, proj):
134          """Remove the object proj from the projection file.          """Remove the object proj from the projection file.
135    
136          Raises a ValueError is proj is not found.          Raises a ValueError is proj is not found.
137          """          """
   
138          self.__projs.remove(proj)          self.__projs.remove(proj)
139            self.issue(PROJECTION_REMOVED, proj)
140    
141      def Replace(self, oldproj, newproj):      def Replace(self, oldproj, newproj):
142          """Replace the object 'oldproj' with 'newproj'.          """Replace the object 'oldproj' with 'newproj'.
143            
144          Raises ValueError if oldproj is not in the file.          Raises ValueError if oldproj is not in the file.
145          """          """
   
         #  
         # see if the projection already exists.  
         # this only works if Projection doesn't override __eq__  
         #  
146          self.__projs[self.__projs.index(oldproj)] = newproj          self.__projs[self.__projs.index(oldproj)] = newproj
147            self.issue(PROJECTION_REPLACED, oldproj, newproj)
148    
149      def GetFilename(self):      def GetFilename(self):
150          """Return the filename where the ProjFile was read or will be          """Return the filename where the ProjFile was read or will be

Legend:
Removed from v.1802  
changed lines
  Added in v.1824

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26