I want to georeference a raster using python
and GDAL
. My current approach is to call gdal_translate
and gdalwarp
using os.system
and an ugly list of ground control points. I’d really like a way to do this natively within python
.
This is the current process I am using:
import os
os.system('gdal_translate -of GTiff -gcp 1251.92 414.538 -7.9164e+06 5.21094e+06 -gcp 865.827 107.699 -7.91651e+06 5.21104e+06 "inraster.tif" "outraster1.tif"')
os.system('gdalwarp -r bilinear -tps -co COMPRESS=NONE "outraster2.tif" "outraster3.tif"')
There is a previous question and answer from 2012 which states that gdal_translate
can be accessed after importing gdal
. I’m not sure if is obsolete, or whether it is wrong but when I run from osgeo import gdal
I do not see gdal.gdal_translate
as an option.
I don’t know if it exists but I would love if I could translate and reproject rasters in a pythonic way. For example:
# translate
gcp_points = [(1251.92, 414.538), (-7.9164e+06, 5.21094e+06)]
gdal.gdal_translate(in_raster, gcp_points, out_raster1)
# warp
gdal.gdalwarp(out_raster1, out_raster2, 'bilinear', args*)
Is such an approach possible?