Search code examples
pythongdal

Python syntax for listing GCPs in gdal.Translate?


I would like to use gdal.Translate to add several GCPs to a Tiff image, but I don't know the correct syntax to do this. help(gdal.TranslateOptions) tells me that I need to use the 'GCPs' kwarg and that this should be a list of GCPs. Does anyone know how I would add the GCPs as a list?

I have done this using the command line and gdal_translate, which is very straightforward, but I would ideally like to do this with Python because the remainder of my code for my project is in Python.

This is what I did in the command line:

gdal_translate -of GTiff -gcp 0 0 -4.717259 52.711651 -gcp 127 0 3.305363 51.733681 -gcp 0 31 -4.992584 51.498657 -gcp 127 31 2.828687 50.546162 -gcp 50 21 -1.762230 51.575226 "C:\PATH_TO_TIF\sds_001.tif" "Output_test.tif”

Solution

  • For anyone who's interested, I ended up just doing it through the command line with the following while in the source directory, looping over all my Tiffs:

    for %i in (*.tif) do gdal_translate -of GTiff -gcp 0 0 -4.717259 52.711651 -gcp 127 0 3.305363 51.733681 -gcp 0 31 -4.992584 51.498657 -gcp 127 31 2.828687 50.546162 -gcp 50 21 -1.762230 51.575226 %i %i.GCP.tif