/[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 996 by bh, Thu May 22 18:21:10 2003 UTC revision 1158 by jonathan, Thu Jun 12 12:40:11 2003 UTC
# Line 11  __version__ = "$Revision$" Line 11  __version__ = "$Revision$"
11  from math import log, ceil  from math import log, ceil
12    
13  from Thuban import _  from Thuban import _
   
14  import shapelib, shptree  import shapelib, shptree
15    
 import gdal  
 from gdalconst import GA_ReadOnly  
   
16  from messages import LAYER_PROJECTION_CHANGED, LAYER_VISIBILITY_CHANGED, \  from messages import LAYER_PROJECTION_CHANGED, LAYER_VISIBILITY_CHANGED, \
17       LAYER_CHANGED       LAYER_CHANGED, LAYER_SHAPESTORE_REPLACED
   
 from color import Color  
18    
19  import classification  import classification
20    
21    from color import Color
22  from base import TitledObject, Modifiable  from base import TitledObject, Modifiable
23    
24    import resource
25    
26    
27  class Shape:  class Shape:
28    
# Line 199  class Layer(BaseLayer): Line 196  class Layer(BaseLayer):
196    
197          self.shapetree = shptree.SHPTree(self.shapefile.cobject(), 2,          self.shapetree = shptree.SHPTree(self.shapefile.cobject(), 2,
198                                           maxdepth)                                           maxdepth)
199            # Set the classification to None if there is a classification
200            # and the new shapestore doesn't have a table with a suitable
201            # column, i.e one with the same name and type as before
202            # FIXME: Maybe we should keep it the same if the type is
203            # compatible enough such as FIELDTYPE_DOUBLE and FIELDTYPE_INT
204          if self.__classification is not None:          if self.__classification is not None:
205              fieldname = self.__classification.GetField()              fieldname = self.__classification.GetField()
206              if fieldname is not None and \              fieldtype = self.__classification.GetFieldType()
207                 not self.store.Table().HasColumn(fieldname):              table = self.store.Table()
208                if (fieldname is not None
209                    and (not table.HasColumn(fieldname)
210                         or table.Column(fieldname).type != fieldtype)):
211                  self.SetClassification(None)                  self.SetClassification(None)
212          self.changed(LAYER_CHANGED, self)          self.changed(LAYER_SHAPESTORE_REPLACED, self)
213    
214      def ShapeStore(self):      def ShapeStore(self):
215          return self.store          return self.store
# Line 212  class Layer(BaseLayer): Line 217  class Layer(BaseLayer):
217      def Destroy(self):      def Destroy(self):
218          BaseLayer.Destroy(self)          BaseLayer.Destroy(self)
219          self.SetClassification(None)          self.SetClassification(None)
220            self.store = self.shapetree = None
221            self.table = self.shapefile = self.shapetable = None
222    
223      def BoundingBox(self):      def BoundingBox(self):
224          """Return the layer's bounding box in the intrinsic coordinate system.          """Return the layer's bounding box in the intrinsic coordinate system.
# Line 350  class Layer(BaseLayer): Line 357  class Layer(BaseLayer):
357      def TreeInfo(self):      def TreeInfo(self):
358          items = []          items = []
359    
360            if hasattr(self, 'filename'):
361                items.append(_("Filename: %s") % self.filename)
362    
363          if self.Visible():          if self.Visible():
364              items.append(_("Shown"))              items.append(_("Shown"))
365          else:          else:
# Line 372  class Layer(BaseLayer): Line 382  class Layer(BaseLayer):
382          return (_("Layer '%s'") % self.Title(), items)          return (_("Layer '%s'") % self.Title(), items)
383    
384    
385    if resource.has_gdal_support():
386        import gdal
387        from gdalconst import GA_ReadOnly
388    
389  class RasterLayer(BaseLayer):  class RasterLayer(BaseLayer):
390    
391      def __init__(self, title, filename, projection = None, visible = True):      def __init__(self, title, filename, projection = None, visible = True):
# Line 397  class RasterLayer(BaseLayer): Line 411  class RasterLayer(BaseLayer):
411    
412          self.bbox = -1          self.bbox = -1
413    
414          #          if resource.has_gdal_support():
415          # temporarily open the file so that GDAL can test if it's valid.              #
416          #              # temporarily open the file so that GDAL can test if it's valid.
417          dataset = gdal.Open(self.filename, GA_ReadOnly)              #
418                dataset = gdal.Open(self.filename, GA_ReadOnly)
419    
420          if dataset is None:              if dataset is None:
421              raise IOError()                  raise IOError()
422    
423          self.UnsetModified()          self.UnsetModified()
424    
# Line 412  class RasterLayer(BaseLayer): Line 427  class RasterLayer(BaseLayer):
427    
428          If the layer has no shapes, return None.          If the layer has no shapes, return None.
429          """          """
430            if not resource.has_gdal_support():
431                return None
432    
433          if self.bbox == -1:          if self.bbox == -1:
434              dataset = gdal.Open(self.filename, GA_ReadOnly)              dataset = gdal.Open(self.filename, GA_ReadOnly)
435              if dataset is None:              if dataset is None:

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26