Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Spatial buffers? #124

Open
idantene opened this issue Sep 22, 2023 · 4 comments
Open

[Question] Spatial buffers? #124

idantene opened this issue Sep 22, 2023 · 4 comments

Comments

@idantene
Copy link

We've noticed that when using odc-stac with e.g.

query = stac_client.search(collections=["sentinel-2-l2a"],
                           bbox=wgs_bbox, datetime=[start_time, end_time],
                           limit=20)
items = query.item_collection()
stack = stac_load(items, bands=bands,
                  resolution=resolution, crs=f"EPSG:{epsg}", groupby="solar_day",
                  bbox=wgs_bbox, chunks={"x": -1, "y": -1}, stac_cfg=STAC_CFG,
                  fail_on_error=fail_on_errors)

We end up getting a slightly larger bounding box then the original bounding box (after converting from WGS to the desired CRS).
I wonder if this is intentional, and/or if there are explicit buffers in how STAC works? Or is it simply due to inaccuracies in WGS84 vs local projection?

When we later stitch several geotiffs together, this is not a particular concern, since the pixels overlap anyway and their values are identical. But when we ingest this data to an indexed database, we end up with duplicate errors that need to be handled 🤔

@Kirill888
Copy link
Member

Kirill888 commented Sep 22, 2023

@idantene

this is as expected. But we still don't have a proper docs page that explains pixel grids to which to link to, for now see #95.

See anchor parameter of stac_load.

@idantene
Copy link
Author

Thanks @Kirill888, that does make sense and I expected something of the sorts.

I'm not sure I follow how to use the anchor argument though. Should I use the AnchorEnum and turn grid snapping off completely, or use the geobox argument to specify the desired extents?

What would be the difference between the two behaviours, given that our bbox is a multiple of resolution in the target crs?

@idantene
Copy link
Author

Also, may I suggest pinning #95 and #54? :)

@Kirill888
Copy link
Member

@idantene

I'm not sure I follow how to use the anchor argument though. Should I use the AnchorEnum and turn grid snapping off completely, or use the geobox argument to specify the desired extents?

Specifying geobox= parameter is the most direct and precise way to control output. If you know bounding box and resolution you want you can just supply geobox=GeoBox.from_bbox(bbox, resolution=gsd, tight=True).

See GeoBox.from_bbox

What would be the difference between the two behaviours, given that our bbox is a multiple of resolution in the target crs?

Imagine axis aligned grid with spacing equal to the ground sampling distance, this grid is "anchored" tox=0 and y=0 (grid includes those two lines). Grid lines are pixel edges. This is the grid we "snap to" by default, that way all the image data loaded at the same resolution will have exactly overlapping pixels so you can just "paste" pixels from one array to another. When supplying anchor=AnchorEnum.FLOATING or tight=True this snapping is turned off, but you might still get an extra pixel on the right bottom, depending on floating point precision and resolution, you can control for that with tol= parameter of GeoBox.from_bbox, but we don't bubble up all those settings to odc.stac.load.

The main difference with supplying anchor= vs geobox= is that with anchor= you can have automatic decisions about resolution and CRS be made by odc-stac, while with geobox= you have to set those in your own code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants