/[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 142 by bh, Fri Feb 15 17:11:04 2002 UTC revision 143 by bh, Tue May 7 14:17:20 2002 UTC
# 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 123  class Layer(BaseLayer): Line 123  class Layer(BaseLayer):
123          self.stroke = stroke          self.stroke = stroke
124          self.stroke_width = stroke_width          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 137  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 178  class Layer(BaseLayer): Line 182  class Layer(BaseLayer):
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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26