Skip to main content
edited tags
Link
gene
  • 55.4k
  • 3
  • 113
  • 191
Source Link
sehan2
  • 457
  • 4
  • 15

How to use osgeo.Warp function in python and replace bash command?

I want to write the following python code without the bash command:

    # warp coordinates of each tile - to correct the origin of the tif files
    for file in tqdm(file_list, desc='warp'):
        bashCommand = "gdalwarp -t_srs EPSG:4647 -overwrite " + file + ' ' + file[:-4] + '.tif'
        process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
        output, error = process.communicate()

I have been trying, but I can not find a working solution. Here is my attempt to solve this:

from osgeo import gdal
input_file = 'input_file_name_string'
output_file = 'output_file_name_string'
input_file = gdal.Open(input_file)
gdal.Warp(output_file, input_file, xRes=5, yRes=5)
dst = None

My ultimate goal is to resolve the error 'Warning 6: gdalbuildvrt does not support positive NS resolution.' and correct the NS resolution with the warp function.