How to project and resample a grid to match another grid with GDAL python?

前端 未结 2 1434
慢半拍i
慢半拍i 2020-12-23 10:58

Clarification: I somehow left out the key aspect: not using os.system or subprocess - just the python API.

I\'m trying to convert a section of a NOAA GTX offset gri

2条回答
  •  被撕碎了的回忆
    2020-12-23 11:36

    If I understand the question correctly, you could accomplish your goal by running gdalwarp and gdal_translate as subprocesses. Just assemble your options then do the following for example:

    import subprocess
    
    param = ['gdalwarp',option1,option2...]
    cmd = ' '.join(param)
    process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout = ''.join(process.stdout.readlines())
    stderr = ''.join(process.stderr.readlines())
    
    if len(stderr) > 0:
        raise IOError(stderr)
    

    It may not be the most elegant solution, but it will get the job done. Once it is run, just load your data into numpy using gdal and carry on your way.

提交回复
热议问题