Page 1 of 1

API error when querying cloudstac with an irregular geometry

Posted: Mon Nov 18, 2024 5:15 pm America/New_York
by ioyler
Good evening! I am getting the following error when querying cloudstac (using pystac_client) with a geometry that has a slightly irregular shape (mostly rectangular, but not quite). The failing polygon is the left half of the working polygon, so it's smaller and I would expect it to pull fewer scenes (~130 is my guess). Am I missing something in the json of the failing geometry that's causing the API error? Or are there limitations to what kinds of polygons can be queried using this method?

APIError: {"message":"If the problem persists please contact cmr-support@earthdata.nasa.gov","errors":["An unexpected error occurred. We have been alerted and are working to resolve the problem.","Request failed with status code 400"]}

Here is a reproducible example with the two geometries:

collections = ['HLSL30.v2.0', 'HLSS30.v2.0']
date_range = '2023-07-20T00:00:00Z/2023-08-02T23:59:59Z'
catalog = pystac_client.Client.open('https://cmr.earthdata.nasa.gov/cloudstac/LPCLOUD')
working_aoi = {'type': 'Polygon',
'coordinates': [[[-116.38922792847926, 47.172870857356614],
[-111.04669813069994, 47.299784861662765],
[-111.05016215472563, 50.864426753115154],
[-116.78676720738619, 50.72067010593359],
[-116.38922792847926, 47.172870857356614]]]}

failing_aoi = {'type': 'Polygon',
'coordinates': [[[-116.38922792847926, 47.172870857356614],
[-116.78676720738619, 50.72067010593359],
[-113.99999998611042, 50.790505192806144],
[-113.99999998611042, 50.00000006475125],
[-113.99999998611042, 48.99999995523382],
[-113.99999998611042, 48.000000013889576],
[-113.99999998611042, 47.229627954994555],
[-116.38922792847926, 47.172870857356614]]]}

search = catalog.search(
collections=collections,
intersects= working_aoi,
datetime=date_range,
limit=100
)

search.matched()
print(f"{search.matched()} scenes found")

search = catalog.search(
collections=collections,
intersects= failing_aoi,
datetime=date_range,
limit=100
)

search.matched()
print(f"{search.matched()} scenes found")

Re: API error when querying cloudstac with an irregular geometry

Posted: Tue Nov 19, 2024 1:03 pm America/New_York
by LP DAACx - dgolon
Please contact cmr-support@earthdata.nasa.gov to report the error.

Re: API error when querying cloudstac with an irregular geometry

Posted: Thu Nov 21, 2024 10:10 am America/New_York
by ioyler
Thanks for the reply. I'm still waiting on a response from cmr-support@earthdata.nasa.gov. I'll let you know when I receive an update.

Re: API error when querying cloudstac with an irregular geometry

Posted: Thu Nov 21, 2024 1:50 pm America/New_York
by LP DAACx - dgolon
Noting for other users seeing this error, please us the email cmr-support@nasa.gov instead.

Re: API error when querying cloudstac with an irregular geometry

Posted: Thu Nov 21, 2024 2:35 pm America/New_York
by dschuck
Your points must be in counter-clockwise order per https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html#g-polygon

Your failing polygon is given in clockwise order, so simply reverse the order of your points and it will likely work. Your working aoi works because the points are already in count-clockwise order.

Re: API error when querying cloudstac with an irregular geometry

Posted: Fri Dec 06, 2024 10:43 am America/New_York
by ioyler
Thanks for your help! I have just confirmed this solution works for me.

For others who may come across this thread, the query worked when I reordered the points of the failing_aoi shapely polygon with this line of code:

aoi_reordered = shapely.geometry.polygon.orient(aoi, sign=1.0)