/[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 73 by bh, Mon Feb 4 19:19:25 2002 UTC revision 147 by bh, Tue May 7 16:39:52 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 175  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            return self.shapetree.find_shapes((left, bottom), (right, top))
193    
194      def SetProjection(self, projection):      def SetProjection(self, projection):
195          """Set the layer's projection"""          """Set the layer's projection"""
196          self.projection = projection          self.projection = projection

Legend:
Removed from v.73  
changed lines
  Added in v.147

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26