You’re right Johanna, sorry for the inconvenience, the above snippet doesn’t work. I will remove it in case other users face the same problem.
In this case, to improve the error you could try to implement the procedure applied on Requests Builder on your own, that is, getting the dimensions by applying Haversine formula on the 4326 bounding box (this will also be an approximation, but it may be more accurate).
Here’s a snippet that may be of use to you:
from sentinelhub import CRS, BBox
from math import radians, cos, sin, asin, sqrt
coord_corners = [12.787420957808262, 54.00935664138693, 12.861358080662724, 54.055644322669615]
def haversine(lat1, lon1, lat2, lon2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees)
"""
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
c = 2 * asin(sqrt(a))
r = 6371
return c * r * 1000
def get_dimensions(bbox, resolution):
xDistance1 = haversine(bbox[3], bbox[0], bbox[3], bbox[2])
xDistance2 = haversine(bbox[1], bbox[0], bbox[1], bbox[2])
yDistance = haversine(bbox[3], bbox[0], bbox[1], bbox[0])
return (max(xDistance1, xDistance2) / resolution, yDistance / resolution)
bbox = BBox(coord_corners, crs= CRS.WGS84)
print(get_dimensions(coord_corners, 10))
This code is just a snippet: the results will also be an approximation and can contain errors
Again, sorry for the inconvience.
Ignasi