/[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 21 by bh, Tue Sep 4 16:45:28 2001 UTC revision 143 by bh, Tue May 7 14:17:20 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  import shapelib, shptree
11    
12  from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \  from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \
13       LAYER_VISIBILITY_CHANGED       LAYER_VISIBILITY_CHANGED
# Line 102  class Layer(BaseLayer): Line 102  class Layer(BaseLayer):
102      """      """
103    
104      def __init__(self, title, filename, projection = None,      def __init__(self, title, filename, projection = None,
105                   fill = None, stroke = _black, visible = 1):                   fill = None, stroke = _black, stroke_width = 1, visible = 1):
106          """Initialize the layer.          """Initialize the layer.
107    
108          title -- the title          title -- the title
# Line 121  class Layer(BaseLayer): Line 121  class Layer(BaseLayer):
121          self.projection = projection          self.projection = projection
122          self.fill = fill          self.fill = fill
123          self.stroke = stroke          self.stroke = stroke
124            self.stroke_width = stroke_width
125          self.shapefile = None          self.shapefile = None
126            self.shapetree = None
127          self.open_shapefile()          self.open_shapefile()
128          # shapetable is the table associated with the shapefile, while          # shapetable is the table associated with the shapefile, while
129          # table is the default table used to look up attributes for          # table is the default table used to look up attributes for
# Line 136  class Layer(BaseLayer): Line 138  class Layer(BaseLayer):
138              self.numshapes = numshapes              self.numshapes = numshapes
139              self.shapetype = shapelib_shapetypes[shapetype]              self.shapetype = shapelib_shapetypes[shapetype]
140              self.bbox = mins[:2] + maxs[:2]              self.bbox = mins[:2] + maxs[:2]
141                #print "building tree for", self.filename, "..."
142                self.shapetree = shptree.SHPTree(self.shapefile.cobject(), 2, 0)
143                #print "done"
144    
145      def BoundingBox(self):      def BoundingBox(self):
146          """Return the bounding box of the layer's shapes in their default          """Return the bounding box of the layer's shapes in their default
# Line 174  class Layer(BaseLayer): Line 179  class Layer(BaseLayer):
179              poly = shape.vertices()[0]              poly = shape.vertices()[0]
180              points = []              points = []
181              for x, y in poly:              for x, y in poly:
182                  points.append(x, y)                  points.append((x, y))
183          return Shape(points)          return Shape(points)
184    
185        def ShapesInRegion(self, box):
186            """Return the ids of the shapes that overlap the box.
187    
188            Box is a tuple (left, bottom, right, top) in the coordinate
189            system used by the layer's shapefile.
190            """
191            left, bottom, right, top = box
192            import time
193            start = time.time()
194            ids = self.shapetree.find_shapes((left, bottom), (right, top))
195            print "ShapesInRegion", time.time() - start
196            return ids
197    
198      def SetProjection(self, projection):      def SetProjection(self, projection):
199          """Set the layer's projection"""          """Set the layer's projection"""
200          self.projection = projection          self.projection = projection
# Line 192  class Layer(BaseLayer): Line 210  class Layer(BaseLayer):
210          stroked."""          stroked."""
211          self.stroke = stroke          self.stroke = stroke
212          self.changed(LAYER_LEGEND_CHANGED, self)          self.changed(LAYER_LEGEND_CHANGED, self)
213    
214        def SetStrokeWidth(self, width):
215            """Set the layer's stroke width."""
216            self.stroke_width = width
217            self.changed(LAYER_LEGEND_CHANGED, self)

Legend:
Removed from v.21  
changed lines
  Added in v.143

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26