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:
Make sure to copy the style from the unrotated to the rotated layer to see the same styling.
You can set the output to take the file name as an additional string which will appear in front of a string specified by you. So what you could do is in the first row, click the ellipses button (shown in red circle), define a path (e.g. to an empty folder) and use a single character like an underscore (shown in green circle). Then click Save.
You will receive another pop up menu for Autofill settings.
Select the following options:
- Autofill mode -
Fill with parameter values
- Parameter to use -
Input layer
Then click OK. I would also suggest setting the Load in QGIS parameter to No
for all your layers. Then run your process.
When it is finished, open the Python Console from the menubar Plugins > Python Console
and run the following code to remove the underscore from the output files, leaving you with the original file name using os.rename:
import os
os.chdir("path/to/folder/")
for fileName in os.listdir("."):
os.rename(fileName, fileName.replace("_", ""))
Best Answer
Looking at the dialog here, you might have some odd POSIX user permission stuff getting in the way. Or possibly DOS line endings (rather than UNIX). Rather than making a file, just do the loop from the command prompt, by typing it out in the terminal. I do this routinely, without the need of making a shell script file.
Typing this the first time, you should see the prompt character in the first column change from
$
to>
(don't type these!) until the end of the loop block:(Note: this is identical to yours, except I replace
%f
with$f
.) After this, you can type the up key to see the previous command.It is shown as a one-line condensed version with semi-colons, which you can use and modify (if needed) for further work from the command prompt.