GDAL – Rotate DEM Efficiently

coordinate systemdemgdalgeotiff-tiff

Is it possible using any of the command line GDL tools such as gdalwarp, etc to perform a rotation of DEM data – a GeoTiff for example?

Anyone know how to do this?


UPDATE1

After clearing out GeoTiff tags and loading my plain Tiff into QGIS with a modified TFW file – I am able to successfully view and export my rotated Tiff DEMs. From what I can tell, the elevation resolution is preserved! However, upon export I decided to view them in MicroDEM and noticed some blocky artifacts. I went back to QGIS and saw the same thing:

MicroDEM
enter image description here

QGIS
enter image description here

Is this perhaps an error in my transform calculations? I did a -10 degree rotation – Started with this:

0.0000925926
0.0000000000
0.0000000000
-0.0000925926
-157.0956018521
20.9603240742

Ended up with this:

0.00009118591
-0.00001607853
-0.00001607853
-0.00009118591
-157.0956018521
20.9603240742

Math look ok there? What else could this be?

Have you seen this before? Can this not be avoided when performing such a rotation?

(Should I move this updated section to a new gis.stackexchange.com question?)


UPDATE2

I performed the same process with a few additional rotation angles, specifically 45° and 90°. The blocky artifacts seem much less severe to the point that they almost don't appear at all. However, another more obvious problem arises at these rotations. The data appears to brighten and become more white overall at certain rotations. In other words, the elevation rises generally in the entire model and detail is therefore lost. First, notice the original view in QGIS:

Original (no rotation), 45° and 90° – respectively:

Original 45 degress 90 degrees

In fact, the same problem is occurring with my original -10 degree rotation (though more subtle):

-10 degrees

This leads me to believe that if the data is rotated at all then I will get this clipping effect. Remember, this is the data as QGIS presents it upon opening the .TIFF file. I have not exported anything or applied any special processes beyond modifying the .TFW file.

What in the world could be going on here? How can I avoid these distortions when rotating the data?


UPDATE3

As noted in the comments, I resolved the first issue using the bi-linear re-sampling. The second issue was resolved by setting the min/max correctly.

Best Answer

You can create a local CRS with an oblique mercator projection, and transform the data with gdalwarp and gdal_translate into it. See my advice here:

Using customized Coordinate System in ArcGIS Desktop?

This should work with 16-bit or grayscale data the same way. Paletted colours shoud be expanded to RGBA in advance.


UPDATE

Using QGIS, create custom CRS without (tmerc) and with (omerc) the rotation, using the same coordinates for the center of projection:

+proj=tmerc +lat_0=51.4 +lon_0=7 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
+proj=omerc +lat_0=51.4 +lonc=7 +alpha=-10 +k=1 +x_0=0 +y_0=0 +gamma=0 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs

In a first run, use Raster -> Projections -> Warp on your tif to the rotation point:

gdalwarp -overwrite -s_srs EPSG:4326 -t_srs "+proj=tmerc +lat_0=51.4 +lon_0=7 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" -of GTiff D:/Download/N51E007.hgt D:/Download/51_7.tif

In QGIS, you will not see a difference, because the pixel values have not changed. Then use Raster -> Conversion -> Translate:

gdal_translate -a_srs "+proj=omerc +lat_0=51.4 +lonc=7 +alpha=-10 +k=1 +x_0=0 +y_0=0 +gamma=0 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" -of GTiff D:/Download/51-7.tif D:/Download/51-7rot.tif

and the result looks like expected:

enter image description here

Make sure to copy the style from the unrotated to the rotated layer to see the same styling.

Related Question