[GIS] changing negative pixel spacing to positive

gdalgeotiff-tiff

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.

Best Answer

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).