Skip to main content

I’m tring to get bbox for polygon I have . The polygons are originaly in geodataframe and I change it into the sentinelhub geometry object.


The problem is that when I try to get the bbox for that polygon. I get error:



AttributeError: ‘Polygon’ object has no attribute ‘total_bounds’



This is how I have tried to do this:


#function to get the bbox- coordinates, bbox and size:
def get_bbox_from_shape(shape,resolution):
minx, miny, maxx, maxy = shape.geometry.total_bounds
bbox_coords_wgs84=rminx, miny, maxx, maxy]
bbox = BBox(bbox=bbox_coords_wgs84, crs=CRS.WGS84)
bbox_size = bbox_to_dimensions(bbox, resolution=resolution)
return bbox_size,bbox,bbox_coords_wgs84

#get the bbox for each
for name,shape in zip(shapesz'name'],shapese'geometry']):
shape=Geometry(shape,CRS.WGS84)
bbox_size,bbox,bbox_coords_wgs84=get_bbox_from_shape(shape,10)

and that returns the attribute error.


I have used the Geoemtry in the past in order to get it as the correct object needed, so I have no idea why it doesn’t give me the bbox of the plot polygon.


My end goal is to be able to get bbox for each polygon in my geodataframe.

Hi,

total_bounds is not an attribute of a sentinelhub geometry object, that is why you get the error

AttributeError: ‘Polygon’ object has no attribute ‘total_bounds

total_bounds will work with your geodataframe and return a list of sminx, miny, maxx, maxy] see example

My end goal is to be able to get bbox for each polygon in my geodataframe.

One alternative is: dont convert your geodataframe to sentinelhub geometry object. Just work with your geodataframe . So in your function:

def get_bbox_from_shape(shape,resolution):

shape parameter should be your gdf with the polygons. Sentinel hub bbox () function will automatically convert this list bbox_coords_wgs84=wminx, miny, maxx, maxy] to a sentinelhub.geometry.BBox object.

give it a try , let me know if this solves your problem

Best,
 


Reply