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.

Sarath SRK
  • 354
  • 1
  • 3
  • 14
  • 3
    for %%i in (*.tif) do gdal_translate -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR -co TILED=YES %%i C:\Your\NewPath\%%~nxi.tif – user2856 Jun 01 '18 at 07:50
  • Luke's comment will probably get you what you need, but if not, you'd be better off searching on [SO]. This isn't really a GIS question, but a question about batch file variables and constructing paths. – Evil Genius Jun 01 '18 at 11:16
  • @Luke I will check and let you know – Sarath SRK Jun 01 '18 at 13:13
  • @EvilGenius Ok I will post such questions on Stack Overflow next time! – Sarath SRK Jun 01 '18 at 13:14
  • @Luke Thanks for your valuable information! I have used for %%i in (*.tif) do gdal_translate -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR -co TILED=YES %%i D:\work\YCBCR\%%~nxi to get output images in the same name at defined path. Post it as answer, so that it may help others – Sarath SRK Jun 04 '18 at 04:28
  • 1
    If you are interested in an explanation why Luke's code works take a look at https://gis.stackexchange.com/questions/262218/batch-processing-multiple-files-with-mcc-lidar/263106#263106. – Andre Silva Jul 02 '18 at 02:44

0 Answers0