-
Notifications
You must be signed in to change notification settings - Fork 535
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
Standardize or normalize use of bounds and bounding boxes #525
Comments
@brendan-ward That's an excellent framing of the problem for inverted y-axis rasters! I'll take a deeper look next week but for now, initial thought is that we might be able to handle this is an implementation detail within |
Side note: I'm working on a project right now that uses positive y-axis rasters and I'm documenting some of difficulties in this gist. |
Reviving this idea, and TBH I'm a little confused, maybe due to terminology or maybe due to the current implementation. My confusion stems from
So the dataset "bounds" returns a "BoundingBox" in bounds (xmin, ymin, xmax, ymax) order. 😕 Maybe we need more distinct terminology and variable names to match? Seems like the toughest problem is knowing when to use bounds vs boundingbox - to truly support south-up (postiive affine.e) rasters we'd need to sweep the codebase for all uses of the bounds-like objects, determine if they were intended to use bounds or BoundingBox, and normalize as appropriate. Some of those assumptions might go down into the GDAL C api too. Another things I'd like to do here is start building a test suite of expected behaviors with positive affine.e raster. @brendan-ward what are your thoughts on getting this in 1.0. It seems like a big lift but it might be an API-changing deal so it might be better to tackle sooner than later. Maybe there are smaller steps we can take towards this for 1.0, leaving the bulk of the work to post-1.0? |
@perrygeo I think this is a good idea to cleanup pre 1.0, but not sure how to go about it. I've been confused and frustrated by the differences between them in the past and would like to save users from the same. I think that bounds in the standard xmin, ymin, xmax, ymax are easy to deal with in many places; they align nicely with the general concept of a bounding box. It is the translation of those to the terms left, bottom, right, top that requires the affine or at least knowing the sign of y. I'm not sure why the latter was used for Are you thinking of going as deep as changing the return from |
I'm with you, I've definitely struggled with inverted rasters and continue to do so every time I encounter them. I don't think we should do anything as drastic as change src.bounds behavior but... Big picture, my goal would be to just use any raster regardless of the sign of I think the reality is that an assumption of Maybe shorter term, we just need to document what does and does not currently work with inverted y rasters as a first step towards clarifying our thoughts. |
I'm confused by the discussion and unsure of what the problem and solutions are. If you're examining a dataset that has a "north-oriented" CRS, the Y coordinate in that space decreases from the upper left while the numpy array index increases. These two coordinate systems are flipped with respect to each other and that's just how it is. Better documentation and abstractions are good, but the difference between the coordinate systems isn't a problem to solve. Is there a problem with "south-oriented" datasets? I never see these in practice, but let's get one of these into our test fixtures, see what it breaks, and work out how to deal with it. |
It's not a matter of the CRS, rather the interpretation of the transform when the affine.e is > 0. They're not common but I've seen them mainly is weather/climate data distributed at NetCDFs When we grab the bounds, they are in WNES order.
Lots of code assumes that bounds are WSEN. For example, with S/N flipped...
That's just one example, the assumption that the row 0, column 0 is the north-west corner pops up all over the place. Having a handle on where things fail is the first step - I'll add that test raster and start building a test suite for it. |
For reference: http://www.gdal.org/frmt_netcdf.html.
Wonderful.
@perrygeo I'm curious about what's going on in these NetCDF files with the flipped transforms. Is the georeferencing underspecified? Can this config option (bottom of the driver page) help?
(Hashtag GDAL config option) |
Yeah, NETCDFs have their own issues (I forgot to mention https://github.com/perrygeo/ncvrt which I created to deal with them). Let's put that format aside for now. The issue I'm trying to isolate here is problems that arise from having a positive affine.e value. Technically a 100 x 100 geotiff with a
If you read it as an array, flipped the bands (
. |
I wrote a flip.py script to test this out.
No unit tests yet but just a high-level overview of what
I should note that QGIS does a great job of rendering inverted Y rasters properly. |
And on the Changing these to be correct for inverted rasters may have implications and break other things. For instance, mask handles the inverted case explicitly and relies on the current behavior of |
@perrygeo presumably if this was standardized upstream, then we could remove the specific handling in Thank you for the thorough testing of rio commands here! |
I'm gonna punt on this for 1.0 - however we decide to deal with positive affine.e rasters it will not break the API so it can be added post-1.0. For now, this ticket can serve to document the known bugs with inverted y datasets. |
Our use of bounds and bounding boxes is not altogether consistent (see comments on a recent PR).
Part of the problem is that bounds in some contexts, especially those derived from features follow the
(xmin, ymin, xmax, ymax)
convention.Most other places in rasterio, e.g., the
bounds
property on a raster, follow rasterio'sBoundingBox
representation(left, bottom, right, top)
. This relies on the affine transform of the raster.Depending on the direction of the y dimension, these two forms may be equivalent (where y is decreasing from upper left). In the case of y increasing from upper left (e.g.,
Affine.identity()
or numpy indexes), these are not equivalent, and issues ensue when we don't account for this.One approach would be to create a series of normalization functions, that we could use for interchange between functions that expect one form or another. I've started to do so, but I'm now questioning this approach.
One downside to this approach is that the user needs to know when to use these based on the function signature or docstring of the method they are passing bounds or bounding boxes into.
Overall, this presents mostly in dealing with interactions between features and rasters, so we can deal with more of the conversions internally in those cases.
@sgillies @perrygeo thoughts?
The text was updated successfully, but these errors were encountered: