How to set the resolution of a Raster using gdal.Grid in python 3?

723 views Asked by At

How to set the output resolution of the raster generated in gdal.Grid? I am using the code below, which produces a TIF with very large cells (~70m) however the data referenced in the vrt (filepath_vrt_in) has data at sub-metre resolution. I get the same result when using inverse distance weighting algorithm, and nearest neighbour at x,y radius of 1m.

from osgeo import gdal
temp_wd = gdal.Grid("C:/Temp/Python-Output-WD-01.TIF", filepath_vrt_in, zfield="Z", algorithm = "nearest:radius1=5.0:radius2=5.0:angle=0.0:nodata=-9999")
temp_wd = None

I have also tried using gdal.Warp as below on the output TIF, which produces a TIF at similar resolution.

temp_warpwd = gdal.Warp("C:/Temp/Python-Output-WD-WARPED-01.TIF", "C:/Temp/Python-Output-WD-01.TIF", xRes=5, yRes=5)
temp_warpwd = None
1

There are 1 answers

0
shmulik90 On

I had the same question and found this solution:

To create for example a GTiff with 100 x 200 pixels write:

from osgeo import gdal
raster= gdal.Grid(destName='output.tif',srcDS='input.shp',format='GTiff',options=gdal.GridOptions(width=100,height=200))