0

I am trying to transform a raster with gdal.Warp in my own python script.

Example:

In the src raster one pixel presents 5 meters and I am trying to transform it where one pixel would present 6,5 meters. I am reading the gdal python documentations and don't know how to actually do this.

Should I just calculate the new width and height from the ratio of 5/6,5 and use it in the gdal.WarpOptions or is there a parameter that takes the pixel per meter data?

What is the dstSRS parameter ?

1

WarpOptions has xRes and yRes arguments (output x & y resolution).

You can either create a WarpOptions object and pass it to gdal.Warp with the options=your_warp_options argument or you can just pass xRes & yRes directly to gdal.Warp as keyword arguments:

options = gdal.WarpOptions(xRes=6.5, yRes=6.5, your other args, eg. resampleAlg=gdal.GRA_Bilinear)
gdal.Warp(destDS, srcDS, options=options)

Or

gdal.Warp(destDS, srcDS, xRes=6.5, yRes=6.5, your other args, eg. resampleAlg=gdal.GRA_Bilinear)
  • Thank you for your answer. I still have some troubles with the warp func. What kind of objects are destDS and srcDS. Can srcDS be a numpy array ? – user8399197 Feb 3 at 10:17
  • Either a gdal.Dataset (opened in write mode for destDS or read mode for srcDS) or file paths for either. No, you can't use a numpy array. Please ask further questions as new questions. – user2856 Feb 3 at 11:18
1

In cases like this I always find that the documentation of the GDAL utility helps me work out what the Python is expecting. So looking at the gdalwarp page leads me to suspect that dstSRS is the same as the -t_srs argument so it's looking for the target SRS (or CRS) - in your case probably the same as the input one.

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.