/[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 6 by bh, Tue Aug 28 15:41:52 2001 UTC revision 171 by bh, Tue May 14 14:16:24 2002 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001 by Intevation GmbH  # Copyright (c) 2001, 2002 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  #  #
# Line 7  Line 7 
7    
8  __version__ = "$Revision$"  __version__ = "$Revision$"
9    
10  import shapelib  from math import log, ceil
11    
12    import shapelib, shptree
13    
14  from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \  from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \
15       LAYER_VISIBILITY_CHANGED       LAYER_VISIBILITY_CHANGED
# Line 102  class Layer(BaseLayer): Line 104  class Layer(BaseLayer):
104      """      """
105    
106      def __init__(self, title, filename, projection = None,      def __init__(self, title, filename, projection = None,
107                   fill = None, stroke = _black, visible = 1):                   fill = None, stroke = _black, stroke_width = 1, visible = 1):
108          """Initialize the layer.          """Initialize the layer.
109    
110          title -- the title          title -- the title
# Line 121  class Layer(BaseLayer): Line 123  class Layer(BaseLayer):
123          self.projection = projection          self.projection = projection
124          self.fill = fill          self.fill = fill
125          self.stroke = stroke          self.stroke = stroke
126            self.stroke_width = stroke_width
127          self.shapefile = None          self.shapefile = None
128            self.shapetree = None
129            self.open_shapefile()
130          # shapetable is the table associated with the shapefile, while          # shapetable is the table associated with the shapefile, while
131          # table is the default table used to look up attributes for          # table is the default table used to look up attributes for
132          # display          # display
# Line 136  class Layer(BaseLayer): Line 141  class Layer(BaseLayer):
141              self.shapetype = shapelib_shapetypes[shapetype]              self.shapetype = shapelib_shapetypes[shapetype]
142              self.bbox = mins[:2] + maxs[:2]              self.bbox = mins[:2] + maxs[:2]
143    
144                # estimate a good depth for the quad tree. Each depth
145                # multiplies the number of nodes by four, therefore we
146                # basically take the base 4 logarithm of the number of
147                # shapes.
148                if self.numshapes < 4:
149                    maxdepth = 1
150                else:
151                    maxdepth = int(ceil(log(self.numshapes / 4.0) / log(4)))
152    
153                self.shapetree = shptree.SHPTree(self.shapefile.cobject(), 2,
154                                                 maxdepth)
155    
156      def BoundingBox(self):      def BoundingBox(self):
157          """Return the bounding box of the layer's shapes in their default          """Return the bounding box of the layer's shapes in their default
158          coordinate system"""          coordinate system"""
# Line 173  class Layer(BaseLayer): Line 190  class Layer(BaseLayer):
190              poly = shape.vertices()[0]              poly = shape.vertices()[0]
191              points = []              points = []
192              for x, y in poly:              for x, y in poly:
193                  points.append(x, y)                  points.append((x, y))
194          return Shape(points)          return Shape(points)
195    
196        def ShapesInRegion(self, box):
197            """Return the ids of the shapes that overlap the box.
198    
199            Box is a tuple (left, bottom, right, top) in the coordinate
200            system used by the layer's shapefile.
201            """
202            left, bottom, right, top = box
203            return self.shapetree.find_shapes((left, bottom), (right, top))
204    
205      def SetProjection(self, projection):      def SetProjection(self, projection):
206          """Set the layer's projection"""          """Set the layer's projection"""
207          self.projection = projection          self.projection = projection
# Line 191  class Layer(BaseLayer): Line 217  class Layer(BaseLayer):
217          stroked."""          stroked."""
218          self.stroke = stroke          self.stroke = stroke
219          self.changed(LAYER_LEGEND_CHANGED, self)          self.changed(LAYER_LEGEND_CHANGED, self)
220    
221        def SetStrokeWidth(self, width):
222            """Set the layer's stroke width."""
223            self.stroke_width = width
224            self.changed(LAYER_LEGEND_CHANGED, self)

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26