I am trying to understand how to properly set up an affine transformation using Rasterio. I have read through guides online and I have used the format provided but for some reason, it does not seem to be working with my data.

Here is an example of the affine transformation

transform = rasterio.Affine(0.016540527, 0, -134.49954, 0, -0.007511139, 69.13232)

My understanding is that when using this transformation the origin (0,0) should be the lower left corner of the raster (that is what I am expecting). However, when I test it using the following code

x, y = transform * (0, 0)

The origin ends up being (-134.49954, 69.13232) - the top left corner of the raster. Therefore when saving the image using this transformation it ends up being inverted. The south side of the raster is the top and the north side of the raster is the bottom.

The code I am using to save the raster is this

                with rasterio.open(
                ) as tif_dataset:
                    tif_dataset.write(data, 1)

Could there be an issue with the data itself? Possibly with the way it is being saved as a GeoTiff?

  • No, the origin of an image (0, 0) is top left, i.e. min(lon), max(lat).
    – user2856
    Commented Aug 16, 2023 at 20:34
  • @user2856 thanks for clarifying - that's helpful. I guess then it is likely the numpy array itself that is the issue and it needs to be inverted.
    – JMurfitt
    Commented Aug 17, 2023 at 12:49
  • numpy.flipud
    – user2856
    Commented Aug 17, 2023 at 23:20

1 Answer 1


Production of transform and (0, 0) coordinates should give you upper left corner of dataset. It is even notified in rasterio documentation https://rasterio.readthedocs.io/en/stable/quickstart.html#dataset-georeferencing I think the problem is with your image. Btw, I don't know what raster means in your code, but if you write data it makes more sense to use

height = data.shape[0], 

in creation options

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.