/[thuban]/trunk/thuban/Thuban/Model/layer.py
ViewVC logotype

Diff of /trunk/thuban/Thuban/Model/layer.py

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

revision 1158 by jonathan, Thu Jun 12 12:40:11 2003 UTC revision 1219 by bh, Mon Jun 16 17:42:54 2003 UTC
# Line 9  Line 9 
9  __version__ = "$Revision$"  __version__ = "$Revision$"
10    
11  from math import log, ceil  from math import log, ceil
12    import warnings
13    
14  from Thuban import _  from Thuban import _
15  import shapelib, shptree  import shapelib, shptree
# Line 165  class Layer(BaseLayer): Line 166  class Layer(BaseLayer):
166    
167          self.UnsetModified()          self.UnsetModified()
168    
169        def __getattr__(self, attr):
170            """Access to some attributes for backwards compatibility
171    
172            The attributes implemented here are now held by the shapestore
173            if at all. For backwards compatibility pretend that they are
174            still there but issue a DeprecationWarning when they are
175            accessed.
176            """
177            if attr in ("table", "shapetable"):
178                value = self.store.Table()
179            elif attr == "shapefile":
180                value = self.store.Shapefile()
181            elif attr == "filename":
182                value = self.store.FileName()
183            else:
184                raise AttributeError, attr
185            warnings.warn("The Layer attribute %r is deprecated."
186                          " It's value can be accessed through the shapestore"
187                          % attr, DeprecationWarning, stacklevel = 2)
188            return value
189    
190      def SetShapeStore(self, store):      def SetShapeStore(self, store):
191          self.store = store          self.store = store
192          self.shapefile = self.store.Shapefile()          shapefile = self.store.Shapefile()
         self.shapetable = self.store.Table()  
         if hasattr(self.store, "FileName"):  
             self.filename = self.store.FileName()  
         self.table = self.shapetable  
193    
194          numshapes, shapetype, mins, maxs = self.shapefile.info()          numshapes, shapetype, mins, maxs = shapefile.info()
195          self.numshapes = numshapes          self.numshapes = numshapes
196          self.shapetype = shapelib_shapetypes[shapetype]          self.shapetype = shapelib_shapetypes[shapetype]
197    
# Line 194  class Layer(BaseLayer): Line 211  class Layer(BaseLayer):
211          else:          else:
212              maxdepth = int(ceil(log(self.numshapes / 4.0) / log(4)))              maxdepth = int(ceil(log(self.numshapes / 4.0) / log(4)))
213    
214          self.shapetree = shptree.SHPTree(self.shapefile.cobject(), 2,          self.shapetree = shptree.SHPTree(shapefile.cobject(), 2,
215                                           maxdepth)                                           maxdepth)
216          # Set the classification to None if there is a classification          # Set the classification to None if there is a classification
217          # and the new shapestore doesn't have a table with a suitable          # and the new shapestore doesn't have a table with a suitable
# Line 217  class Layer(BaseLayer): Line 234  class Layer(BaseLayer):
234      def Destroy(self):      def Destroy(self):
235          BaseLayer.Destroy(self)          BaseLayer.Destroy(self)
236          self.SetClassification(None)          self.SetClassification(None)
         self.store = self.shapetree = None  
         self.table = self.shapefile = self.shapetable = None  
237    
238      def BoundingBox(self):      def BoundingBox(self):
239          """Return the layer's bounding box in the intrinsic coordinate system.          """Return the layer's bounding box in the intrinsic coordinate system.
# Line 275  class Layer(BaseLayer): Line 290  class Layer(BaseLayer):
290          return (min(llx), min(lly), max(urx), max(ury))          return (min(llx), min(lly), max(urx), max(ury))
291    
292      def GetFieldType(self, fieldName):      def GetFieldType(self, fieldName):
293          if self.table.HasColumn(fieldName):          table = self.store.Table()
294              return self.table.Column(fieldName).type          if table.HasColumn(fieldName):
295                return table.Column(fieldName).type
296          return None          return None
297    
298      def NumShapes(self):      def NumShapes(self):
# Line 291  class Layer(BaseLayer): Line 307  class Layer(BaseLayer):
307    
308      def Shape(self, index):      def Shape(self, index):
309          """Return the shape with index index"""          """Return the shape with index index"""
310          shape = self.shapefile.read_object(index)          shape = self.store.Shapefile().read_object(index)
311    
312          if self.shapetype == SHAPETYPE_POINT:          if self.shapetype == SHAPETYPE_POINT:
313              points = shape.vertices()              points = shape.vertices()

Legend:
Removed from v.1158  
changed lines
  Added in v.1219

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26