4

I am doing calculations in Google Earth Engine using several images from different sources, but I don't find a way to snap or pixel-align the layers before calculations. Also, I don't seem to understand how GEE is working, because the same function lets me snap image1 to image2, but does nothing if I try to snap image2 to image1.

These are snapshots of my two images, and a third one where I have changed transparency to show that pixels do not overlap:

image1 (a soil layer) enter image description here

image2 (land cover from Copernicus) enter image description here

image1 and image2 (50% transparency) - notice the misalignment between pixels enter image description here

This is what I get when I print .projection() for both layers (notice that some of the extent values differ) image1 enter image description here

image2 enter image description here

Then, I want to snap/align image2 using image1 as a template. This is the code I'm using:

var image2_aligned = image2.reproject({
  crs: image1.projection().crs(),
  scale: image1.projection().nominalScale()
})

However, the result is still misaligned image1 and image2_aligned (50% transparency) enter image description here

The result is identical to my original layer

But, if I do the opposite, align image1 using image2 as a template, the same code works as I expect

var image1_aligned = image1.reproject({
  crs: image2.projection().crs(),
  scale: image2.projection().nominalScale()
})

image1_aligned and image2 (50% transparency) enter image description here

Why does this happen? How can I get a version of image2 that aligns pixels in image1?

Also, a less practical question. Because I come from QGIS and R, my old mindset kind of wants to do that step manually but, is it necessary at all? GEE would do the calculations even if pixels are not aligned, but I feel it's better to align the images myself than letting it out for GEE, as I wouldn't have control over what it's doing under the shadow (but not that there is anything particularly important to control in this case...)

Final note: I've read documentation for GEE images, .projection(), and .reproject(), but I'm too new to make sense of everything. Also, I've read answers to this other question, but I don't think it's exactly the same... or, at least, it's not helping me finding a solution.

3
  • 1
    One question per Question, please.
    – Vince
    Aug 24, 2020 at 11:38
  • did You find an answer to that? Jun 8, 2022 at 9:38
  • It might help you to read the warning given here developers.google.com/earth-engine/guides/… If you want full control over the alignment, you need to specify the crs and transform, not crs and scale. Apr 30, 2023 at 12:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.