TransWikia.com

Generating a GDAL script through the QGIS Georeferencer

Geographic Information Systems Asked on July 29, 2021

For several months, I have been georeferencing files manually using the Georeferencer plugin within QGIS. I am now attempting to automate this process using GDAL. The Georeferencer provides a “Generate GDAL script” option, which creates the following commands:

gdal_translate -of GTiff -gcp 774.73 -338 -88.52 34.37 -gcp 1012.17 -215.136 -81.22 27.48 -gcp 972.709 -486.055 -77.76 36.67 asciiMAE20121001.asc testoutput1
gdalwarp -r near -order 1 -co COMPRESS=NONE testoutput1 testoutput2

When I run this script, however, the georeferenced raster is placed about 40 degrees further west than where it should be, and 7 degrees further south. Manually using the Georeferencer plugin continues to georeference the raster correctly. I think the problem is with the gdalwarp, because the raster is just shifted too far from where it should be. The placement of the values within it appears to be correct, so it looks like the gdal_translate worked correctly.

Does anyone know why the GDAL script produced by the Georeferencer would produce a raster displaced from the raster produced manually by the plugin?

3 Answers

Assuming you have saved the output of your GCP points, can you compare the values in this file with the auto-generated script? I've noticed that the script rounds values; I wonder if this could be introducing a source of error.

Answered by djq on July 29, 2021

The comment by @user30184 indicates the problem. The manual shows that the arguments to gcp are "pixel line easting northing elevation". For the qgis generated gdal script to be correct, you must have loaded a raster without a reference system. Otherwise the first two arguments for each -gcp will be wrong.

I removed the spatial information from my tif with this:

gdal_translate -co PROFILE=BASELINE in.tif out.tif

Then I loaded out.tif and found the ground control points using qgis and exported the script.

Alternatively you could convert the first two arguments of each of your existing gcps to the pixel and line of the image.

Answered by Tedward on July 29, 2021

I have encountered this problem recently as well so I checked the pixel coordinate system used by the QGIS Georeferencer and noticed that the origin (upper left corner) is at (1000, 1000) instead of (0, 0).

You might want to check if your origin is not (0, 0) and apply necessary offsets to the pixel coordinates and see if gives you the right output (it worked for me).

Answered by R.K. on July 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP