I've created a virtual raster using gdalbuildvrt, which covers a large extent (England) at a high resolution. The data is fairly sparse, focused around the coastlines with no files covering inland areas. I'm trying to read the data in Python using rasterio.

When I try to invert the affine transformation (to get world coordinates converted to pixel coordinates) I getting the following error:

>>> layer.affine
Affine(0.0002777778000000001, 0.0, -5.5000000044,
       0.0, -0.0002777778000000001, 55.0000000836)
>>> layer.affine.__invert__()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Python27\lib\site-packages\affine-1.0-py2.7.egg\affine\__init__.py", line 407, in __invert__
    "Cannot invert degenerate transform")
affine.TransformNotInvertibleError: Cannot invert degenerate transform

I don't get this error accessing the individual raster files. I have some idea of what it means, but not how to work around it. Perhaps it needs approaching in a different way? How do I access this data without having to worry about which file it's stored in?

  • I cannot find docs for __invert__ but I suspect it is a general matrix inversion procedure. The 2 by 3 matrix returned by layer.affine cannot be inverted as a matrix (because it is not square). If I am correct, you would need to apply a procedure intended specifically for this shorthand representation of affine transformations, perhaps invertAffineTransform.
    – whuber
    Aug 4, 2014 at 12:41

1 Answer 1


Inverting the transform isn't the way to go. Try the dataset's index() method or its code: https://github.com/mapbox/rasterio/blob/master/rasterio/io.py#L62.

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.