Getting a blank when clipping image to specific polygon

I followed the instructions both here
https://www.sentinel-hub.com/faq/how-can-i-clip-image-specific-polygon
and
https://github.com/sentinel-hub/sentinelhub-py/issues/37

From those i came up with

testBoxCoordinates=[-86.161166,13.521312,-86.160418,13.522696]

testBox=BBox(bbox=testBoxCoordinates, crs=CRS.WGS84)

geometryWKT = ‘POLYGON((-86.160791 13.522606,-86.160989 13.522462,-86.161045 13.522387,-86.161049 13.522316,-86.16109 13.522236,-86.161024 13.522079,-86.161166 13.521843,-86.161072 13.521601,-86.161009 13.521576,-86.16105 13.52146,-86.160921 13.521368,-86.160904 13.521312,-86.160778 13.521313,-86.160657 13.521438,-86.160649 13.521674,-86.160569 13.521895,-86.160512 13.522006,-86.160532 13.522087,-86.1606 13.522288,-86.160557 13.522346,-86.160526 13.522391,-86.160499 13.522522,-86.160463 13.522622,-86.160418 13.522696,-86.160602 13.522643,-86.160696 13.522608,-86.160791 13.522606))’

img_request = WmsRequest(data_folder=‘testdata’, layer=‘TRUE_COLOR’, bbox=testBox, time=(‘2016-12-31’,‘2017-12-31’), width=512, height=856, image_format=MimeType.TIFF,
instance_id=INSTANCE_ID,custom_url_params={CustomUrlParam.GEOMETRY: geometryWKT})

img_request.get_data(save_data=True)

It returns proper images when i run it without the custom_url_params, so im wondering what i am doing wrong.

Hi Newton,

it turns out there is a small bug in sentinelhub Python package. When using WGS 84 the package takes coordinates in order lon-lat however before calling Sentinel Hub services it has to reverse them to lat-lon. This is correctly handled for bounding box coordinates however for polygon the coordinates are not reversed (but they should be).

We will fix this in the next release of the package. Until then you can make it work if you reverse the coordinates yourself before calling WmsRequest. Hence for your example it would work if you use this:

POLYGON((13.522606 -86.160791,13.522462 -86.160989,13.522387 -86.161045,13.522316 -86.161049,13.522236 -86.16109,13.522079 -86.161024,13.521843 -86.161166,13.521601 -86.161072,13.521576 -86.161009,13.52146 -86.16105,13.521368 -86.160921,13.521312 -86.160904,13.521313 -86.160778,13.521438 -86.160657,13.521674 -86.160649,13.521895 -86.160569,13.522006 -86.160512,13.522087 -86.160532,13.522288 -86.1606,13.522346 -86.160557,13.522391 -86.160526,13.522522 -86.160499,13.522622 -86.160463,13.522696 -86.160418,13.522643 -86.160602,13.522608 -86.160696,13.522606 -86.160791))

Thanks for letting us know about this issue.

We have just released new package version 2.4.2 where this issue has been fixed. Now the coordinates of the CustomUrlParam.GEOMETRY parameter should be specified in order longitude-latitude as it would be expected (and same as order of BBox coordinates).

Thanks again for raising the issue.

Awesome thanks for the update!

1 Like