3

This is the code that I am using to print the bounds of my shapefile.

import fiona
import shapely
import shapely.geometry

fc = fiona.open("filename.shp")
shapefile_record = fc.next()
shape = shapely.geometry.asShape(shapefile_record['geometry'])
polygon = shapefile_record['geometry']
print polygon.bounds

However, I keep getting an error that says:

AttributeError: 'dict' object has no attribute 'bounds'

Can someone guide me as to where I am wrong?

2

With your example, polygon is a standard Python dict object that represents a GeoJSON geometry, which only uses standard data types, with no fancy geospatial properties.

But you can convert polygon into a shapely geometry, as you have done with shape

polygon = shapefile_record['geometry']
shape = shapely.geometry.asShape(polygon)
print(shape.bounds)
0

Fiona also has a bounds function.

>>> import fiona
>>> with fiona.open("input.shp") as src:
...     feat = next(src)
...     print fiona.bounds(feat)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.