0

I have a folder which contains DEM in .hgt. I want to convert them via GDAL. So to convert a single file, it's gdal_translate -of 'GTiff' N16E122.hgt N16E122.tif. To do it in Powershell, I figured it's something like a for-loop which contains the GDAL command but parameterized.

I tried this based on this comment https://stackoverflow.com/a/18847285/12779978

$files = Get-ChildItem "C:\Users\me\Desktop\New folder"
foreach ($f in $files){
    $outfile = $f.FullName + ".tif"
    Get-Content $f.FullName | gdal_translate -of GTiff *.hgt $f.tif | Set-Content $outfile
}

The command returns 4 FAILURE: No target dataset specified. errors and the result is a .hgt.tif file for each of the input file like N16E122.hgt.tif. I've tried numerous combinations for the $outfile variable and the GDAL dst_dataset parameter but nothing works.

enter image description here

enter image description here

2

Solved. The .tif files are loading properly in QGIS.

$files = Get-ChildItem .
foreach ($f in $files){
$path = "C:\Users\Me\Desktop\New folder\"
$infile = $f.FullName
$outfile = $path + $f.BaseName + ".tif"
Get-Content $f.FullName | gdal_translate -of GTiff $infile $outfile
}

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.