API error when querying cloudstac with an irregular geometry
API error when querying cloudstac with an irregular geometry
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")
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:
-
- User Services
- Posts: 422
- Joined: Mon Sep 30, 2019 10:00 am America/New_York
- Has thanked: 31 times
- Been thanked: 8 times
- Contact:
Re: API error when querying cloudstac with an irregular geometry
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.
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.
Re: API error when querying cloudstac with an irregular geometry
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.
-
- User Services
- Posts: 422
- Joined: Mon Sep 30, 2019 10:00 am America/New_York
- Has thanked: 31 times
- Been thanked: 8 times
- Contact:
Re: API error when querying cloudstac with an irregular geometry
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.
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.
Re: API error when querying cloudstac with an irregular geometry
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.
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
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)
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)