I have a bug with one application that does not handle negative pixel spacing values. Therefore I would like to change the negative pixel values of my images (geotif) into positive values (while keeping the georeferencing, of course.

I've tried with gdalwarp and gdal_translate but the output still remains in negative values. My workaround was to create a tfw, ten "manually" edit it to get positive Y values and changing the origin to lower left instead of upper left. However, I would like to know if there is an easier (and faster) method to achieve this. If possible using gdal.

EDIT: I don't want to flip the images : I want an output that is georeferenced with positive pixel spacing in X and Y (so the origin should be at the bottom left) but pixels mustn't move. I've tried editing the geotransform but this does not modify the row order.


By reading this GDAL ticket http://trac.osgeo.org/gdal/ticket/4977 it should be possible to flip a GeoTIFF by using a negative pixel size in ModelPixelScaleTag. On Y-axis this would mean positive pixel size for GDAL. However, as you can read from the ticket, this trick does not work for you and even if it works you should still place the origin to lower left.

Instead or editing the world file you can probably use .VRT file http://www.gdal.org/gdal_vrttut.html and edit the GeoTransform element e.g.

<GeoTransform>440720.0, 60.0, 0.0, 3751320.0, 0.0, -60.0</GeoTransform>

Even in this case you must also move the origin to lower left in the VRT file. I believe that finally you will decide to write a few rows of Python code for overriding the default GeoTransform and turn the Y pixel size into positive and slide the Y coordinate by (pixel size Y) * (image height).

  • I did try vrt but it didn't help. I'll try overriding the geotransform in Python. – radouxju Jan 26 '15 at 14:54
  • Did you test VRT with a baseline tiff without GeoTIFF tags gdal_translate -of GTiff -co PROFILE=BASELINE? It is unclear for me which metadata has most weight: geotiff tags, VRT, aux.xml. I know that world file has less power than geotiff tags. – user30184 Jan 26 '15 at 15:04
  • in my case, the application read the tiff pointed by the vrt, so if this tiff has negative values, it doesn't work. – radouxju Jan 26 '15 at 15:19
  • -co profile baseline remove all georeferencing information. In my case this temporarily solves my problem because I can now run my application without georeferencing, but I still need the Python code to rewrite my georeferenced header at the end. I am just surprised that there is no other solution than overwriting the geotransform with Python, so I'll wait a little bit before I accept your answer "just in case" it attracts a more direct solution. – radouxju Jan 26 '15 at 15:25
  • If you want to play, try gdalbuildvrt flip1.vrt geotiff.tif and gdalbuildvrt flip2.vrt flip1.vrt. Edit GeoTransform in flip2.vrt to positive Y pixel. Gdalinfo from edited flip2.vrt (which points to flip1.vrt and further to unedited original geotiff) reports Pixel Size = (10.000000000000000,10.000000000000000) so the trick seems to override geotiff tags but still the origin must be moved also in the VRT. Read also mail-archive.com/gdal-dev@lists.osgeo.org/msg06165.html. – user30184 Jan 26 '15 at 15:31

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.