I'm trying to export numpy ndarray that I have to TIFF using rasterio. I have the transform of the image:

>>>(583932.1992386435, 10.0, 0, 2223772.1491772938, 0, -10.0)

When I use this when I save the raster I recieve error :

    with rasterio.open('test.tiff', 
                       nodata=None, # change if data has nodata value
                       transform=transf) as dst:
        dst.write(vi[:,:,0], 1)
        dst.write(vi[:,:,1], 2)
        dst.write(vi[:,:,2], 3)

TypeError: GDAL-style transforms have been deprecated. This exception will be raised for a period of time to highlight potentially confusing errors, but will eventually be removed.

I haven't found any posts in regard to this error. How can I change it? How can I save my result ndarray int TIFF given the transform?

2 Answers 2


Use the Affine.from_gdal method to convert any existing GDAL-style transforms:

from affine import Affine

transf = (583932.1992386435, 10.0, 0, 2223772.1491772938, 0, -10.0)
afn = Affine.from_gdal(*transf)

Now pass afn to rasterio's transform parameter.


Explanation of the why at https://github.com/mapbox/rasterio/blob/master/docs/topics/migrating-to-v1.rst#migrating-to-rasterio-10

Explanation of how to fix your code with this issue comment https://github.com/mapbox/rasterio/issues/1830#issuecomment-601446758. First link is useful for order of args between old style e.g GDAL geotransform and new style e.g affine.Affine

In your case,

#(c, a, b, f, d, e)
transf = (583932.1992386435, 10.0, 0, 2223772.1491772938, 0, -10.0)

should become

from rasterio import Affine as A

#affine.Affine(a, b, c,
#              d, e, f)

transf = A(10.0, 0.0, 583932.1992386435,
            0.0, -10.0, 2223772.1491772938,)

In the rasterio.open, continue to use transform=transf as it accepts an Affine object.

Your Answer

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

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