Shapely bbox geometry to sentinelhub bbox

There is a small error in your get_bbox_from_shape function: shape is already a shapely geometry, and as such, has no attribute geometry (this is what the first error says: AttributeError: ‘Polygon’ object has no attribute ‘geometry’)

Changing the line

minx, miny, maxx, maxy = shape.geometry.total_bounds

to

minx, miny, maxx, maxy = shape.bounds

works.

Beware that your code works correctly only for geometries that are in WGS84 coordinate reference system.

Your second approach is also possible, and has an error due to imports… If you do

from sentinelhub import BBox, CRS, Geometry

you can create bounding boxes from your geometries as

bbox = Geometry(shape, CRS.WGS84).bbox

(shape would be i in your for loop).

1 Like