i have some trouble warping one raster to different resolution. My input is a one channel tiff with. I know the geo-coordinates of x_min and y_max. I also know that the pixel resolution is 5 meters. I now want to warp the same raster to pixel resolution of 6.5 meters.

Input in the function is the numpy array and the upper left corner coordinates with the src and dst pixel resolution.

My code is:

def resample_raster(raster, raster_x0, raster_ymax, src_xres, src_yres, dst_xres, dst_yres):


    dstAR=np.empty((dst_height, dst_width))

    srcDS.SetGeoTransform((raster_x0,src_xres,0, raster_ymax, 0, -src_yres ) )
    srcDS.SetGeoTransform((raster_x0,dst_xres,0, raster_ymax, 0, -dst_yres ) )

    gdal_warp_options=osgeo.gdal.WarpOptions(xRes=dst_xres,yRes=dst_yres, resampleAlg=osgeo.gdal.GRA_NearestNeighbour)

    osgeo.gdal.Warp(dstDS, srcDS,options=gdal_warp_options)


    return new_raster

The function gives me an empty array or is killed.


I am not certain of what you try to achieve but I have two sugestions:

  1. Follow this idea on how to resize a numpy array using scipy.
  2. Use gdal.Warp to warp a tiff to a different resolution. For example:
import gdal
infn = '/path/to/source.tif'
outfn = '/path/to/target.tif'

resample_alg = 'near'

ds = gdal.Warp(outfn, infn, warpoptions=dict(xRes=xres, yRes=yres, resampleAlg=resample_alg)
ds = None

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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