def __iter__(self):
""" Returns generator over shapefile rows.
Note:
The first column is an id field, taken from the id value of each shape
The middle values are taken from the property_schema
The last column is a string named geometry, which has the wkt value, the type is geometry_type.
"""
# These imports are nere, not at the module level, so the geo
# support can be an extra
self.start()
vfs, shp_file, layer_index = self._open_file_params()
with fiona.open(shp_file, vfs=vfs, layer=layer_index) as source:
if source.crs.get('init') != 'epsg:4326':
# Project back to WGS84
project = partial(pyproj.transform,
pyproj.Proj(source.crs, preserve_units=True),
pyproj.Proj(from_epsg('4326'))
)
else:
project = None
yield self.headers
for i,s in enumerate(source):
row_data = s['properties']
shp = asShape(s['geometry'])
row = [int(s['id'])]
for col_name, elem in row_data.items():
row.append(elem)
if project:
row.append(transform(project, shp))
else:
row.append(shp)
yield row
self.finish()
评论列表
文章目录