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 |
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 |
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 |
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 |