0

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?

10
  • What error do you get with the second approach?
    – mmomtchev
    Jan 26, 2022 at 10:24
  • I have no error, but only the first file is execuuted. I want to execute all of them included in the code. Is it possible?
    – Geographos
    Mar 9, 2022 at 15:52
  • how do you run those commands?
    – mmomtchev
    Mar 9, 2022 at 17:56
  • I use osgeo4shell
    – Geographos
    Mar 9, 2022 at 19:05
  • If you execute the two commands of your second approach separately, have you a good result ? Mar 11, 2022 at 9:37

1 Answer 1

1
+100

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.
6
  • OK I will put them in one line and back to you
    – Geographos
    Aug 11, 2022 at 10:53
  • I hope you do not plan to write everything on one line. You will need one line for each command just like in my example.
    – user30184
    Aug 11, 2022 at 13:36
  • This is what I've done and the result was, that just the first one was executed
    – Geographos
    Aug 12, 2022 at 13:57
  • 'ZLEVEL' is not recognized as an internal or external command, operable program or batch file. this is the error I am getting right now
    – Geographos
    Aug 12, 2022 at 14:21
  • It is really amazing. That error indicates that the command on a single line breaks for some reason so that ZLEVEL is not recognized to be a parameter for gdal_translate but a new command. And that only one line was executed may indicates that there is something odd add the end of the line, not just the normal CRLF end-of-line character. It may be that your text editor inserts some non-ascii characters into the batch file.
    – user30184
    Aug 12, 2022 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.