GDAL georeference multiple PNG images as GEOTIFF with different size and extents

gdalgeoreferencinggeotiff-tiff

Following my problem described here:

Georeferencing PNG image by GDAL in QGIS

I would like to make some batch image georeference in GDAL. Unfortunately I couldn't find the reasonable solution for it. The problems, which were undertaken in the links below:

https://stackoverflow.com/questions/58532501/batch-command-for-a-gdal-script
Georeferencing multiple images as GeoTIFF (same size and extents) in QGIS
Georeference multiple jpg through GDAL

was applied for the same size and extensions.

I need this solution for various sizes and extensions, as I deal with the big area including even 20 files such as described in the problem before.

My code so far looks like this:

  gdal_translate --config GDAL_CACHEMAX 1024 -co NUM_THREADS=ALL_CPUS -co COMPRESS=DEFLATE -co 
  ZLEVEL=9 -co TILED=YES -a_srs EPSG:4326 -a_ullr 21 51 22 50 C:\my\GDAL\cloakpN50E021.png 
  C:\my\GDAL\cloakpN50E021.tif -a_ullr 22 48 23 49 C:\my\GDAL\cloakpN49E022.png 
  C:\my\GDAL\cloakpN49E022.tif -a_ullr 23 48 24 49 C:\my\GDAL\cloakpN49E023.png 
  C:\my\GDAL\cloakpN49E023.tif

but I got an error:

   **ERROR 6: Too many command options**

https://stackoverflow.com/questions/41560506/gdal-translate-error-6-too-many-command-options-ot

My second approach was:

  gdal_translate --config GDAL_CACHEMAX 1024 -co NUM_THREADS=ALL_CPUS -co COMPRESS=DEFLATE -co 
  ZLEVEL=9 -co TILED=YES -a_srs EPSG:4326 -a_ullr 22 48 23 49 C:\my\GDAL\cloakpN49E022.png 
  C:\my\GDAL\cloakpN49E022.tif
  gdal_translate --config GDAL_CACHEMAX 1024 -co NUM_THREADS=ALL_CPUS -co COMPRESS=DEFLATE -co 
  ZLEVEL=9 -co TILED=YES -a_srs EPSG:4326 -a_ullr 23 48 24 49 C:\my\GDAL\cloakpN49E023.png 
  C:\my\GDAL\cloakpN49E023.tif

but only the first file came trhough.

What is the option for bulk georeferencing when the extension and size remains different?

Best Answer

This is a batch file "bat_test.bat" with one line for each gdal_translate command:

gdal_translate --config GDAL_CACHEMAX 1024 -co NUM_THREADS=ALL_CPUS -co COMPRESS=DEFLATE -co ZLEVEL=9 -co TILED=YES -a_srs EPSG:4326 test.png   test_out1.tif
gdal_translate --config GDAL_CACHEMAX 1024 -co NUM_THREADS=ALL_CPUS -co COMPRESS=DEFLATE -co ZLEVEL=9 -co TILED=YES -a_srs EPSG:4326 test.png   test_out2.tif

Running it performs two GDAL commands

>bat_test

gdal_translate --config GDAL_CACHEMAX 1024 -co NUM_THREADS=ALL_CPUS -co COMPRESS=DEFLATE -co ZLEVEL=9 -co TILED=YES -a_srs EPSG:4326 test.png   test_out1.tif
Input file size is 256, 256
0...10...20...30...40...50...60...70...80...90...100 - done.

gdal_translate --config GDAL_CACHEMAX 1024 -co NUM_THREADS=ALL_CPUS -co COMPRESS=DEFLATE -co ZLEVEL=9 -co TILED=YES -a_srs EPSG:4326 test.png   test_out2.tif
Input file size is 256, 256
0...10...20...30...40...50...60...70...80...90...100 - done.
Related Question