/[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 492 by jonathan, Mon Mar 10 10:44:57 2003 UTC revision 701 by bh, Thu Apr 17 16:18:48 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2002 by Intevation GmbH  # Copyright (c) 2001, 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  # Jonathan Coles <[email protected]>  # Jonathan Coles <[email protected]>
# Line 15  from Thuban import _ Line 15  from Thuban import _
15    
16  import shapelib, shptree  import shapelib, shptree
17    
18  from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \  from messages import LAYER_PROJECTION_CHANGED, LAYER_VISIBILITY_CHANGED, \
19       LAYER_VISIBILITY_CHANGED       LAYER_CHANGED
20    
21  from color import Color  from color import Color
22    
# Line 102  class Layer(BaseLayer): Line 102  class Layer(BaseLayer):
102    
103          TITLE_CHANGED -- The title has changed.          TITLE_CHANGED -- The title has changed.
104          LAYER_PROJECTION_CHANGED -- the projection has changed.          LAYER_PROJECTION_CHANGED -- the projection has changed.
         LAYER_LEGEND_CHANGED -- the fill or stroke attributes have changed  
   
105      """      """
106    
107      def __init__(self, title, filename, projection = None,      def __init__(self, title, filename, projection = None,
108                   fill = Color.None,                   fill = Color.Transparent,
109                   stroke = Color.Black,                   stroke = Color.Black,
110                   lineWidth = 1,                   lineWidth = 1,
111                   visible = 1):                   visible = 1):
# Line 118  class Layer(BaseLayer): Line 116  class Layer(BaseLayer):
116          projection -- the projection object. Its Inverse method is          projection -- the projection object. Its Inverse method is
117                 assumed to map the layer's coordinates to lat/long                 assumed to map the layer's coordinates to lat/long
118                 coordinates                 coordinates
119          fill -- the fill color or Color.None if the shapes are not filled          fill -- the fill color or Color.Transparent if the shapes are
120          stroke -- the stroke color or Color.None if the shapes are not stroked                  not filled
121            stroke -- the stroke color or Color.Transparent if the shapes
122                    are not stroked
123          visible -- boolean. If true the layer is visible.          visible -- boolean. If true the layer is visible.
124    
125          colors are expected to be instances of Color class          colors are expected to be instances of Color class
# Line 147  class Layer(BaseLayer): Line 147  class Layer(BaseLayer):
147          # tries to set its parent layer the variable will exist          # tries to set its parent layer the variable will exist
148          #          #
149          self.__classification = None          self.__classification = None
150            self.__setClassLock = False
151    
152    
153          self.SetClassification(None)          self.SetClassification(None)
# Line 190  class Layer(BaseLayer): Line 191  class Layer(BaseLayer):
191              self.shapefile.close()              self.shapefile.close()
192              self.shapefile = None              self.shapefile = None
193              self.shapetree = None              self.shapetree = None
194            self.SetClassification(None)
195          self.table.Destroy()          self.table.Destroy()
196    
197      def BoundingBox(self):      def BoundingBox(self):
# Line 197  class Layer(BaseLayer): Line 199  class Layer(BaseLayer):
199    
200          If the layer has no shapes, return None.          If the layer has no shapes, return None.
201          """          """
         # The bbox will be set by open_shapefile just as we need it  
         # here.  
         self.open_shapefile()  
202          return self.bbox          return self.bbox
203    
204      def LatLongBoundingBox(self):      def LatLongBoundingBox(self):
# Line 218  class Layer(BaseLayer): Line 217  class Layer(BaseLayer):
217              return None              return None
218    
219      def GetFieldType(self, fieldName):      def GetFieldType(self, fieldName):
         self.open_shapefile()  
220          info = self.table.field_info_by_name(fieldName)          info = self.table.field_info_by_name(fieldName)
221          if info is not None:          if info is not None:
222              return info[0]              return info[0]
# Line 227  class Layer(BaseLayer): Line 225  class Layer(BaseLayer):
225    
226      def NumShapes(self):      def NumShapes(self):
227          """Return the number of shapes in the layer"""          """Return the number of shapes in the layer"""
         self.open_shapefile()  
228          return self.numshapes          return self.numshapes
229    
230      def ShapeType(self):      def ShapeType(self):
231          """Return the type of the shapes in the layer.          """Return the type of the shapes in the layer.
232          This is either SHAPETYPE_POINT, SHAPETYPE_ARC or SHAPETYPE_POLYGON.          This is either SHAPETYPE_POINT, SHAPETYPE_ARC or SHAPETYPE_POLYGON.
233          """          """
         self.open_shapefile()  
234          return self.shapetype          return self.shapetype
235    
236      def Shape(self, index):      def Shape(self, index):
237          """Return the shape with index index"""          """Return the shape with index index"""
         self.open_shapefile()  
238          shape = self.shapefile.read_object(index)          shape = self.shapefile.read_object(index)
239    
240          if self.shapetype == SHAPETYPE_POINT:          if self.shapetype == SHAPETYPE_POINT:
# Line 276  class Layer(BaseLayer): Line 271  class Layer(BaseLayer):
271          If 'clazz' is None a default classification is created          If 'clazz' is None a default classification is created
272          """          """
273    
274            # prevent infinite recursion when calling SetLayer()
275            if self.__setClassLock: return
276    
277            self.__setClassLock = True
278    
279          if clazz is None:          if clazz is None:
280                if self.__classification is not None:
281                    self.__classification.SetLayer(None)
282              self.__classification = classification.Classification()              self.__classification = classification.Classification()
283          else:          else:
   
             # prevent infinite recursion when calling SetLayer()  
             if clazz == self.__classification:  
                 return  
   
284              self.__classification = clazz              self.__classification = clazz
285              self.__classification.SetLayer(self)              try:
286                    self.__classification.SetLayer(self)
287                except ValueError:
288                    self.__setClassLock = False
289                    raise ValueError
290    
291            self.changed(LAYER_CHANGED, self)
292    
293          self.changed(LAYER_LEGEND_CHANGED, self)          self.__setClassLock = False
294    
295      def ClassChanged(self):      def ClassChanged(self):
296          """Called from the classification object when it has changed."""          """Called from the classification object when it has changed."""
297          self.changed(LAYER_LEGEND_CHANGED, self)          self.changed(LAYER_CHANGED, self)
298    
299      def TreeInfo(self):      def TreeInfo(self):
300          items = []          items = []

Legend:
Removed from v.492  
changed lines
  Added in v.701

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26