Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plan for replacing GDAL transform arrays with Affine instances #86

Closed
sgillies opened this issue May 29, 2014 · 2 comments
Closed

Plan for replacing GDAL transform arrays with Affine instances #86

sgillies opened this issue May 29, 2014 · 2 comments
Milestone

Comments

@sgillies
Copy link
Member

The Goal

In Rasterio versions up to 0.8, GDAL geotransform arrays were used throughout: in the internals when calling GDAL functions and in the Rasterio Python interfaces. In Rasterio 1.0 GDAL's arrays will be for internal use only and Rasterio will deal in instances of affine.Affine or 6-element tuples that can be converted directly to instances of that class.

The Plan

Arguments

In the methods and functions with transform arguments, we will try to support both the new objects and the GDAL geotransform arrays up until 1.0 by sniffing sequences for characteristic signs of being a GDAL array. Here's the function to be used:

def tastes_like_gdal(t):
    return t[2] == t[4] == 0.0 and t[1] > 0 and t[5] < 0

Geospatial rasters very rarely have non-zero rotation coefficients and GDAL has them at indexes 2 and 4. GDAL puts the pixel sizes at indexes 1 and 5 and the later should be negative. When a GDAL geotransform argument is received, Rasterio will raise a future warning like this:

$ python -Wall examples/reproject.py
/Users/sean/code/rasterio/rasterio/__init__.py:100: FutureWarning: GDAL-style transforms are deprecated and will not be supported in Rasterio 1.0.
  FutureWarning)

Note that deprecation warnings get ignored unless warnings are turned on with the -W option.

Return Values

For the methods and properties that return a transformation object, we need a different approach. Starting with version 0.9, properties like .transform will raise a deprecation warning. We will also add parallel .affine property, values of which are instances of affine.Affine. At version 1.0, we will switch the values of .transform over to affine.Affine and leave the .affine attribute as a deprecated alias.

This plan will finish for Rasterio the harmonization proposed in #80.

cc @brendan-ward @mwtoews @AsgerPetersen

@sgillies sgillies added this to the 0.9 milestone May 29, 2014
@sgillies sgillies added the docs label May 30, 2014
@sgillies sgillies changed the title Add .affine attribute instead of changing sense of .transform Plan for replacing GDAL transform arrays with Affine instances May 30, 2014
sgillies pushed a commit that referenced this issue May 30, 2014
All tests pass, all examples are working.

TODO: docs.
TimoRoth added a commit to TimoRoth/oggm that referenced this issue Jun 23, 2017
See rasterio/rasterio#86 for reference.
Fixes a couple hundret deprecation warnings that come up during testing.
TimoRoth added a commit to TimoRoth/oggm that referenced this issue Jun 23, 2017
See rasterio/rasterio#86 for reference.
Fixes a couple hundred deprecation warnings that come up during testing.
@johanvdw
Copy link
Contributor

johanvdw commented Dec 4, 2017

What is the recommended way to have code working with both rasterio 0.36 and the 1.0* releases?

I currently use dst.affine, which works fine under both versions, but generates a shitload of warning on 1.0*. Do I really have to check for the rasterio version and adopt the behaviour?

@johanvdw
Copy link
Contributor

johanvdw commented Dec 4, 2017

I dislike checking for a version, so I came up with this solution, may be useful for others.

from affine import Affine
...
if isinstance(dst.transform, Affine):
    transform = dst.transform
else:
    transform = dst.affine  # for compatibility with rasterio 0.36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants