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$ |
45 |
# raw data. |
# raw data. |
46 |
RAW_SHAPEFILE = "RAW_SHAPEFILE" |
RAW_SHAPEFILE = "RAW_SHAPEFILE" |
47 |
|
|
48 |
|
# Raw data in well-known text format |
49 |
|
RAW_WKT = "RAW_WKT" |
50 |
|
|
51 |
|
|
52 |
class ShapefileShape: |
class ShapefileShape: |
53 |
|
|
69 |
ys.append(y) |
ys.append(y) |
70 |
return (min(xs), min(ys), max(xs), max(ys)) |
return (min(xs), min(ys), max(xs), max(ys)) |
71 |
|
|
72 |
|
def ShapeID(self): |
73 |
|
return self.shapeid |
74 |
|
|
75 |
def Points(self): |
def Points(self): |
76 |
"""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""" |
77 |
shape = self.shapefile.read_object(self.shapeid) |
shape = self.shapefile.read_object(self.shapeid) |
199 |
""" |
""" |
200 |
return self.bbox |
return self.bbox |
201 |
|
|
202 |
def ShapesInRegion(self, box): |
def ShapesInRegion(self, bbox): |
203 |
"""Return the ids of the shapes that overlap the box. |
"""Return an iterable over the shapes that overlap the bounding box. |
204 |
|
|
205 |
Box is a tuple (left, bottom, right, top) in the coordinate |
The bbox parameter should be the bounding box as a tuple in the |
206 |
system used used in the shapefile. |
form (minx, miny, maxx, maxy) in the coordinate system of the |
207 |
""" |
shape store. |
208 |
left, bottom, right, top = box |
""" |
209 |
return self.shapetree.find_shapes((left, bottom), (right, top)) |
# Bind a few globals to locals to make it a bit faster |
210 |
|
cls = ShapefileShape |
211 |
|
shapefile = self.shapefile |
212 |
|
|
213 |
|
left, bottom, right, top = bbox |
214 |
|
for i in self.shapetree.find_shapes((left, bottom), (right, top)): |
215 |
|
yield cls(shapefile, i) |
216 |
|
|
217 |
|
def AllShapes(self): |
218 |
|
"""Return an iterable over the shapes in the shape store.""" |
219 |
|
for i in xrange(self.NumShapes()): |
220 |
|
yield ShapefileShape(self.shapefile, i) |
221 |
|
|
222 |
def Shape(self, index): |
def Shape(self, index): |
223 |
"""Return the shape with index index""" |
"""Return the shape with index index""" |
276 |
""" |
""" |
277 |
return self.shapestore.ShapesInRegion(bbox) |
return self.shapestore.ShapesInRegion(bbox) |
278 |
|
|
279 |
|
def AllShapes(self): |
280 |
|
"""Return an iterable over the shapes in the shape store. |
281 |
|
|
282 |
|
This method is simply delegated to the shapestore the |
283 |
|
DerivedShapeStore was instantiated with. |
284 |
|
""" |
285 |
|
return self.shapestore.AllShapes() |
286 |
|
|
287 |
def ShapeType(self): |
def ShapeType(self): |
288 |
"""Return the type of the shapes in the layer. |
"""Return the type of the shapes in the layer. |
289 |
|
|