stac-utils / pystac-client

Python client for searching STAC APIs
https://pystac-client.readthedocs.io
Other
154 stars 47 forks source link

Point intersection with raster seems inaccurate #727

Closed amit-hazan closed 3 weeks ago

amit-hazan commented 3 weeks ago

I frequently perform operations to search for items that intersect with a given point. Generally, this approach works well, and I get the correct item. However, I have noticed that, in some cases, the point does not seem to intersect with the resulting item as expected. Here is a code snippet that demonstrates the issue:

from datetime import date
from pystac_client import Client

geometry = {"type":"Point", "coordinates":[16.319,59.4436]}
target_date = date(2020, 9, 15)

client = Client.open("https://planetarycomputer.microsoft.com/api/stac/v1", headers=[])

items = client.search(
    collections="sentinel-2-l2a",
    intersects=geometry,
    datetime=str(target_date),
)

One of the resulting items is 'S2A_MSIL2A_20200915T101031_R022_T33VWG_20200918T101504'. However, when I download one of its assets (a band) and attempt to locate the point on the raster, the point appears to be outside of the raster bounds.

Any insights into why this might be happening or how to resolve this would be greatly appreciated.

TomAugspurger commented 3 weeks ago

The intersects will always consider the geometry of the STAC item. Your point should be inside (or at least intersecting) with the item's geometry, otherwise there's a bug on the server side (pgstac in the Planetary Computer's case).

The geometry of the Item should be close to the geometry of the raster assets, but it might not be perfect. https://www.element84.com/geospatial/the-stactools-raster-footprint-utility goes into this.

Depending on the item / assets, there might be some bad metadata that should be addressed in the service serving these items (or the stactools package). Either way, I don't think this is an issue in pystac-client.

amit-hazan commented 3 weeks ago

It seems that the raster footprint was the problem since it's inaccurate. Thanks for your help!