1

This question may seem strange at first, but what I need to do is to move a raster image over another raster image and align them perfectly. Both rasters have the very same size and resolution - one is a Landsat band and another is a product of bands analysis, so this movement includes change of coordinates.

Why are they in different places? In Correcting Landsat images shifted by strangely high distance using ArcMap? I said I have rasters straight from Earth Explorer covering some area that are misplaced from 100 m even up to 40 km (don't ask me why, sensor callibration?).

I will explain it by listing what I do:

  1. For every image create an RGB composition (for better terrain recognition)
  2. Choose one image as a reference one (which seems to be correct according to my GPS data)
  3. Using ArcMap's Shift tool I move each RGB image individually to it's correct place looking at the reference raster (RGB product only, bands are left untouched)
  4. Now I would like to automatically apply movement of each band of each image to corresponding RGB image created from these bands (move them to their "correct place")
  5. Afterwards I would use Snap raster option to align pixel misplacement if needed

Point 4. is where I'm stuck. I would prefer not to have to use Shift tool for each image, because selecting correct X and Y shift is problematic if you don't remember by how much you have already moved the corresponding RGB.

  • This is a trivial exercise if you just use Python. It wouldn't be more than a dozen lines of code. – Vince Mar 14 '17 at 20:37
1

Thanks to the hint given by Vince, I wrote this really short Python script:

from osgeo import gdal

# here I open both files, the one to be shifted with '1' flag (write-permission)
band = gdal.Open("path to image I want to shift", 1)
reference = gdal.Open("path to reference image")

# read origin values from reference image
target = reference.GetGeoTransform()

# example origin values:
# (440025.0, 30.0, 0.0, 8923215.0, 0.0, -30.0)

# the main action - set new values to origin of band image (i.e. change position of its top-left corner)
band.SetGeoTransform(target)

# after shifting I found the projection gets reset and needs to be specified again, so I import it from reference image)
band.SetProjection(reference.GetProjection())

Put it in a loop to automate shifting of multiple images.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.