7 |
|
|
8 |
"""Data source abstractions""" |
"""Data source abstractions""" |
9 |
|
|
10 |
|
from __future__ import generators |
11 |
|
|
12 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
13 |
# $Source$ |
# $Source$ |
14 |
# $Id$ |
# $Id$ |
66 |
ys.append(y) |
ys.append(y) |
67 |
return (min(xs), min(ys), max(xs), max(ys)) |
return (min(xs), min(ys), max(xs), max(ys)) |
68 |
|
|
69 |
|
def ShapeID(self): |
70 |
|
return self.shapeid |
71 |
|
|
72 |
def Points(self): |
def Points(self): |
73 |
"""Return the coordinates of the shape as a list of lists of pairs""" |
"""Return the coordinates of the shape as a list of lists of pairs""" |
74 |
shape = self.shapefile.read_object(self.shapeid) |
shape = self.shapefile.read_object(self.shapeid) |
196 |
""" |
""" |
197 |
return self.bbox |
return self.bbox |
198 |
|
|
199 |
def ShapesInRegion(self, box): |
def ShapesInRegion(self, bbox): |
200 |
"""Return the ids of the shapes that overlap the box. |
"""Return an iterable over the shapes that overlap the bounding box. |
201 |
|
|
202 |
Box is a tuple (left, bottom, right, top) in the coordinate |
The bbox parameter should be the bounding box as a tuple in the |
203 |
system used used in the shapefile. |
form (minx, miny, maxx, maxy) in the coordinate system of the |
204 |
""" |
shape store. |
205 |
left, bottom, right, top = box |
""" |
206 |
return self.shapetree.find_shapes((left, bottom), (right, top)) |
left, bottom, right, top = bbox |
207 |
|
for i in self.shapetree.find_shapes((left, bottom), (right, top)): |
208 |
|
yield ShapefileShape(self.shapefile, i) |
209 |
|
|
210 |
|
def AllShapes(self): |
211 |
|
"""Return an iterable over the shapes in the shape store.""" |
212 |
|
for i in xrange(self.NumShapes()): |
213 |
|
yield ShapefileShape(self.shapefile, i) |
214 |
|
|
215 |
def Shape(self, index): |
def Shape(self, index): |
216 |
"""Return the shape with index index""" |
"""Return the shape with index index""" |
269 |
""" |
""" |
270 |
return self.shapestore.ShapesInRegion(bbox) |
return self.shapestore.ShapesInRegion(bbox) |
271 |
|
|
272 |
|
def AllShapes(self): |
273 |
|
"""Return an iterable over the shapes in the shape store. |
274 |
|
|
275 |
|
This method is simply delegated to the shapestore the |
276 |
|
DerivedShapeStore was instantiated with. |
277 |
|
""" |
278 |
|
return self.shapestore.AllShapes() |
279 |
|
|
280 |
def ShapeType(self): |
def ShapeType(self): |
281 |
"""Return the type of the shapes in the layer. |
"""Return the type of the shapes in the layer. |
282 |
|
|
285 |
""" |
""" |
286 |
return self.shapestore.ShapeType() |
return self.shapestore.ShapeType() |
287 |
|
|
288 |
|
def RawShapeFormat(self): |
289 |
|
"""Return the raw data format of the shapes. |
290 |
|
|
291 |
|
This method is simply delegated to the shapestore the |
292 |
|
DerivedShapeStore was instantiated with. |
293 |
|
""" |
294 |
|
return self.shapestore.RawShapeFormat() |
295 |
|
|
296 |
def NumShapes(self): |
def NumShapes(self): |
297 |
"""Return the number of shapes in the shapestore.""" |
"""Return the number of shapes in the shapestore.""" |
298 |
return self.shapestore.NumShapes() |
return self.shapestore.NumShapes() |