124 |
# safer to always work with absolute paths. |
# safer to always work with absolute paths. |
125 |
self.filename = os.path.abspath(filename) |
self.filename = os.path.abspath(filename) |
126 |
|
|
|
self.shapefile = shapelib.ShapeFile(self.filename) |
|
127 |
self.dbftable = table.DBFTable(filename) |
self.dbftable = table.DBFTable(filename) |
128 |
self.table = ShapeTable(self, session.TransientDB(), self.dbftable) |
self.table = ShapeTable(self, session.TransientDB(), self.dbftable) |
129 |
|
self._open_shapefile() |
130 |
|
|
131 |
|
def _open_shapefile(self): |
132 |
|
self.shapefile = shapelib.ShapeFile(self.filename) |
133 |
self.numshapes, shapetype, mins, maxs = self.shapefile.info() |
self.numshapes, shapetype, mins, maxs = self.shapefile.info() |
134 |
if self.numshapes: |
if self.numshapes: |
135 |
self.bbox = mins[:2] + maxs[:2] |
self.bbox = mins[:2] + maxs[:2] |
208 |
form (minx, miny, maxx, maxy) in the coordinate system of the |
form (minx, miny, maxx, maxy) in the coordinate system of the |
209 |
shape store. |
shape store. |
210 |
""" |
""" |
211 |
|
# Bind a few globals to locals to make it a bit faster |
212 |
|
cls = ShapefileShape |
213 |
|
shapefile = self.shapefile |
214 |
|
|
215 |
left, bottom, right, top = bbox |
left, bottom, right, top = bbox |
216 |
for i in self.shapetree.find_shapes((left, bottom), (right, top)): |
for i in self.shapetree.find_shapes((left, bottom), (right, top)): |
217 |
yield ShapefileShape(self.shapefile, i) |
yield cls(shapefile, i) |
218 |
|
|
219 |
def AllShapes(self): |
def AllShapes(self): |
220 |
"""Return an iterable over the shapes in the shape store.""" |
"""Return an iterable over the shapes in the shape store.""" |