1

I planned to use gdal_translate to convert raster from uncompressed RGB geotiff to compressed(JPEG compression) YCBCR geotiff as a batch process. So I have created a .bat file using this code

for %%i in (*.tif) do gdal_translate -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR -co TILED=YES %%i %%.tif

The code works fine but the problem is output rasters are created in the same path of input rasters. For example If input raster name is RGB.tif, after processing .bat file output created in the same folder with the name of RGB.tif.tif.

Is there any possibility to store output tiff in a separate directory? I have kept my input rasters in directory D:\work\RGB and I want to store output rasters in D:\work\YCBCR with the same name of Input.

7
  • 3
    for %%i in (*.tif) do gdal_translate -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR -co TILED=YES %%i C:\Your\NewPath\%%~nxi.tif
    – user2856
    Commented Jun 1, 2018 at 7:50
  • Luke's comment will probably get you what you need, but if not, you'd be better off searching on Stack Overflow. This isn't really a GIS question, but a question about batch file variables and constructing paths. Commented Jun 1, 2018 at 11:16
  • @Luke I will check and let you know
    – Sarath SRK
    Commented Jun 1, 2018 at 13:13
  • @EvilGenius Ok I will post such questions on Stack Overflow next time!
    – Sarath SRK
    Commented Jun 1, 2018 at 13:14
  • 1
    If you are interested in an explanation why Luke's code works take a look at gis.stackexchange.com/questions/262218/…. Commented Jul 2, 2018 at 2:44

0

Browse other questions tagged or ask your own question.