Skip to content

xy_coords introduces unexpected (?) pixel shift #68

@maawoo

Description

@maawoo

Hi all!
Either the shift in pixels that I have observed is actually unexpected and needs to somehow be adjusted in the to_coords function or I'm simply missing something or misunderstanding the concept behind geotransforms and it's only unexpected for me at the moment. Hope someone can help me out either way 🙂

In the following screenshots, the colored image is always the original raster, while the greyscale image is always the one created with these lines of code:

scene_stack = stackstac.stack(items=stac_obj, xy_coords=xy_coords, dtype='float32', rescale=False)
scene_stack.rio.to_raster('./scene_stack.tif')

Transform and projection of the raster: 'proj:transform': [10, 0, 399960, 0, -10, 52000020] & 'proj:epsg': 32632 (UTM 32N)

  1. xy_coords=False
    xycoords_false

  2. xy_coords='center' | pixel shift: 0, 1 (expected: 0.5, -0.5)
    xycoords_center

  3. xy_coords='topleft' | pixel shift: -0.5, 0.5 (expected: 0, 0)
    xycoords_topleft

As expected, no shift is observed in (1). Now with (2) and (3), I'm confused. My original raster is a COG following the usual raster conventions, e.g. being top left aligned. Therefore I'd assume that using the default as in (3) results in no pixel shift at all. I'd also assume that the pixels are shifted by 0.5 and -0.5 in x and y respectively when using 'center' as in (2).

Looking forward to hearing some other thoughts on this!

Cheers, Marco

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-future-testAdd a test for this in the future, once tests exist (#26)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions