What can throw the error "type object 'CRS' has no attribute 'WGS84'"?

I’m using sentinel hub bbox function in order to get the bbox details of specific shapefile I have.
The way I used it is as following:

def get_bbox_from_shape(shape,resolution):
    minx, miny, maxx, maxy = shape.geometry.total_bounds
    bbox_coords_wgs84=[minx, 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

bbox_size,bbox,bbox_coords_wgs84=get_bbox_from_shape(shape,10)

The way my script works is that Im using for loop and then for each iteration I get the bouding box of the shape. For some reason I manage to use this script in the first iteration but the 2nd fail with the following error:

AttributeError: type object ‘CRS’ has no attribute ‘WGS84’

Is a bit hard for me to understand the source of this error as the shape in this case is the same as the shape on the first iteration, and then there was the ‘WGS84’ attribute, hence, I don’t understand why this attribute disappeard.

I know i’m not sharing here the full code, but I would like to know from your experience, what could raise such an error?

Best

Reut

Hi @reutkeller,

Is by any chance your CRS object a pyproj.CRS object instead of sentinelhub.CRS object? Even though they have the same name they are not the same.

So I suggest checking:

>>> type(CRS)
<class 'sentinelhub.constants.CRSMeta'>

not sure how to check the type of the crs, as you can see in my script I define it inside the function.
I have tried to check what is the type but I get the same error:

cr=CRS.WGS84

AttributeError: type object 'CRS' has no attribute 'WGS84'

is there anyway I can make sure inside the function that is sentinel hub type? also, the weird thing is that it runs in the first iteration correct but only from the 2nd one it fails with this error. :thinking:

Edit:
I did something like this:

type(CRS)

>>>abc.ABCMeta

Yes, you can always add lines like this into your function:

print(type(CRS))
print(dir(CRS))  # this will show all attributes of an object

Since your object has type abc.ABCMeta I suspect that you define an object named CRS somewhere else your codebase.

A “quick and dirty” solution would be that you add

from sentinelhub import CRS

inside your function get_bbox_from_shape. But I also recommend checking for any other appearances of a CRS object in your code.

1 Like