9

I'm starting to use QGIS for my thesis (environmental physics) and have to admit I'm pretty ignorant about it - I've always used Mathematica or Matlab.

My problem is: I have a raster layer, in .tif format, which is misplaced (I need to move it south and west by 100m). I need to translate (reposition) it, and I have absolutely no idea on how I can do that.

I've tried Affine transform but it doesn't work (doesn't let me select an input layer); I've also read this How to translate (reposition) a raster in Python? but I have to admit I haven't understood much of it, I tried several times but am no good with python.

  • I assume the .tif layer is georeferenced in some way? Which coordinate reference system is stated in the metadata? Quite likely, you only need to correct the CRS settings and the layer will align. – underdark Dec 17 '13 at 20:43
  • thanks for the comment! yes, it is georeferenced, and the coordinate system is the correct one (WGS 84/UTM zone 32N) ..unfortunately the displacement comes from a (badly-written) plugin I need to use, and that I can't change/correct.. hence the need to reposition the layer... – user25031 Dec 17 '13 at 22:30
  • The Affine Transform plugin is for vector layers only. – AndreJ Jan 26 '15 at 12:22
9

ah! I managed to do it, following what's been said in the linked discussion.... (How to translate (reposition) a raster in Python?) apparently it just took me a while to figure how to use the python console! ;) thanks anyways! :)

I used GDAL/Python, from the QGIS Python console! :)

what I wrote was:

from osgeo import gdal
gdal.AllRegister()
rast_src = gdal.Open('filename.tif', 1 )
gt = rast_src.GetGeoTransform()
gtl = list(gt)
gtl[0] -= 200
gtl[3] -= 100
rast_src.SetGeoTransform(tuple(gtl))
rast_src = None

EDIT: switched "gdall.AllRegister()" to "gdal.AllRegister()".

  • There is a one letter typo in the code: gdall.AllRegister is not supposed to be spelled with two "L". (It generats: "'gdall' is not defined") Unfortunately I can't edit it as an edit is required to be at least 6 characters long. – Smerla May 15 '18 at 13:52
  • This answer really helped me out! Only thing I would like to add is to make sure and check your units before doing a transform by typing a print(gtl) function. For instance, my raster was in dd mm ss, and so to figure out how many meters are in a decimal degree, I used the table available here (easier for latitude than longitude!): table for converting meters to decimal degrees – Justin Kray Feb 1 at 8:45
1

The Rasmover plugin should do what you want.

You have to allow for experimental plugins to get it in the plugin list.

The result is a virtual raster file, which you can edit with a text editor to adjust the parameters if needed.

0

In the special case where the raster already has a UTM projection, and you want to move it longitudinally to another UTM zone, I found that gdal_translate can do it. For example, the input raster is in any UTM zone Z, and you want to move it to UTM zone 26 (i.e., the Atlantic Ocean at most latitudes):

gdal_translate -a_srs '+proj=utm +zone=26 +datum=WGS84' input.tif output.tif

The origin and corner coordinates in model space units as reported by gdalinfo remain the same. But the corner coordinates in latitude/longitude change, and the raster really did move to another part of the world.

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.