0

I would like my code to write a tiff file from GRIB while changing the resolution.

So I take file1 (GRIB fmt) and translate it to tiff. The file appears in the folder.

Then, I make a warp, but no file appears. With gdal.driver.Create(..) I can't definitely understand the arguments are required. And I don't understand why Translate doesn't require creating a dataset and warp does.

outpath=path+'tifdatasetraw.tif'
outpath2=path+'tifdatasetraw_warp.tif'
dataset = gdal.Open(file1)
proj=dataset.GetProjection()
dataset=gdal.Translate(outpath,dataset)
gdal.Warp(outpath2, dataset, dstSRS=proj,format='GTiff',xRes=15,yRes=15)
dataset=None

Could somebody who feels at home with GDAL Python explain the philosophy?

It's my first day with this package, but I don't want to make CALL(cmd) for every difficult function.

1

2 Answers 2

2

Why even do this? You use GDAL_translate in your earlier to just include the parameters to change the resolution.

gdal_translate

-tr xres yres : (starting with GDAL 2.0) set target resolution. The values must be expressed in georeferenced units. Both must be positive values. This is mutually exclusive with -outsize and -a_ullr.

-r {nearest (default),bilinear,cubic,cubicspline,lanczos,average,mode}: (GDAL >= 2.0) Select a resampling algorithm.

1
  • 1
    Thank you. Firstly, it's still interesting, why Warp doesn't work. Secondly, what's the python way, you are mentioning the cmd one. Because dataset=gdal.Translate(outpath,dataset,xRes=15,yRes=15) doesn't give anything Mar 4, 2019 at 9:51
1

It is worth to close this question, because the problem still persists, and the code in the question is not clear.

The correct way of reprojecting would be:

outpath=path+'tifdatasetraw.tif'
outpath2=path+'tifdatasetraw_warp.tif'
dataset = gdal.Open(file1)
gdal.Warp(outpath2, dataset, dstSRS=dataset.GetProjection(),format='GTiff', xRes=15,yRes=15)
dataset=None

But in my new question the other code still doesn't create a file, so the problem is with the whole phylosophy of using GDAL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.