API error when querying cloudstac with an irregular geometry

Use this Forum to find information on, or ask a question about, NASA Earth Science data.
Post Reply
ioyler
Posts: 9
Joined: Wed Jul 31, 2024 12:11 pm America/New_York
Answers: 0
Been thanked: 2 times

API error when querying cloudstac with an irregular geometry

by ioyler » Mon Nov 18, 2024 5:15 pm America/New_York

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")

Filters:

LP DAACx - dgolon
User Services
User Services
Posts: 422
Joined: Mon Sep 30, 2019 10:00 am America/New_York
Answers: 0
Has thanked: 31 times
Been thanked: 8 times
Contact:

Re: API error when querying cloudstac with an irregular geometry

by LP DAACx - dgolon » Tue Nov 19, 2024 1:03 pm America/New_York

Please contact cmr-support@earthdata.nasa.gov to report the error.
Subscribe to the LP DAAC listserv by sending a blank email to lpdaac-join@lists.nasa.gov.

Sign up for the Landsat listserv to receive the most up to date information about Landsat data: https://public.govdelivery.com/accounts/USDOIGS/subscriber/new#tab1.

ioyler
Posts: 9
Joined: Wed Jul 31, 2024 12:11 pm America/New_York
Answers: 0
Been thanked: 2 times

Re: API error when querying cloudstac with an irregular geometry

by ioyler » Thu Nov 21, 2024 10:10 am America/New_York

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.

LP DAACx - dgolon
User Services
User Services
Posts: 422
Joined: Mon Sep 30, 2019 10:00 am America/New_York
Answers: 0
Has thanked: 31 times
Been thanked: 8 times
Contact:

Re: API error when querying cloudstac with an irregular geometry

by LP DAACx - dgolon » Thu Nov 21, 2024 1:50 pm America/New_York

Noting for other users seeing this error, please us the email cmr-support@nasa.gov instead.
Subscribe to the LP DAAC listserv by sending a blank email to lpdaac-join@lists.nasa.gov.

Sign up for the Landsat listserv to receive the most up to date information about Landsat data: https://public.govdelivery.com/accounts/USDOIGS/subscriber/new#tab1.

dschuck
Posts: 6
Joined: Thu Oct 31, 2024 9:32 am America/New_York
Answers: 0
Been thanked: 1 time

Re: API error when querying cloudstac with an irregular geometry

by dschuck » Thu Nov 21, 2024 2:35 pm America/New_York

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.

ioyler
Posts: 9
Joined: Wed Jul 31, 2024 12:11 pm America/New_York
Answers: 0
Been thanked: 2 times

Re: API error when querying cloudstac with an irregular geometry

by ioyler » Fri Dec 06, 2024 10:43 am America/New_York

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)

Post Reply