-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add pixel interpretation and casting logic (AREA_OR_POINT
raster metadata) and add new package-level config defaults
#509
Add pixel interpretation and casting logic (AREA_OR_POINT
raster metadata) and add new package-level config defaults
#509
Conversation
AREA_OR_POINT
and package-level config defaultsAREA_OR_POINT
and package-level config defaults
AREA_OR_POINT
and package-level config defaultsAREA_OR_POINT
and with new package-level config defaults
AREA_OR_POINT
and with new package-level config defaultsAREA_OR_POINT
and add new package-level config defaults
…nd coords consistent with them and add tests
AREA_OR_POINT
and add new package-level config defaultsAREA_OR_POINT
and add new package-level config defaults
AREA_OR_POINT
and add new package-level config defaultsAREA_OR_POINT
raster metadata) and add new package-level config defaults
@adehecq @erikmannerfelt The new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A welcome clarification of the pixel interpretation ! 👏 Thanks !
It's still not fully clear in my head why the signs of the half pixels shifts are sometimes different, but maybe you'll be able to help answer.
I'm also curious how often this pixel interpretation will matter. I rarely encountered a case when I needed to care about it.
Oh and maybe this would require adding a small section about this in the documentation?
Thanks for the review! And for the use: Basically, you should never have to touch the default parameters, except if you get a warning 😄 |
Summary
This PR adds support for pixel interpretation (= raster metadata "AREA_OR_POINT") across all functionalities of GeoUtils.
All functions dealing with Raster-Raster, Raster-Point, or coordinate manipulation now have a logic linked to pixel interpretation:
set_area_or_point
or ignore the warning by changing a global warning configuration (details below),For functions that could perform a shift (e.g.,
interp_points
,to_pointcloud
,coords
), shifting with pixel interpretation can be specified with a boolean argumentshift_area_or_pixel
.Additionally, there is a new global configuration dictionary
geoutils.config
which can be used to change the default behaviour at the package scale. For instance,geoutils.config["shift_area_or_point"]=False
removes the shifting according to pixel interpretation everywhere, andgeoutils.config["warn_area_or_point"]=False
removes the warnings associated with pixel interpretation everywhere also.What is pixel interpretation ?
This is a confusing topic, see references linked in #503 for more info.
In short, the metadata "AREA_OR_POINT" determines the pixel interpretation:
GDAL has some internal logic introduced in 2010 to deal with this attribute but it only applies to tie points (GCP): it shifts them by half a pixel when the interpretation is "Point".
Rasterio derives coordinates independently of this metadata, and thus we have to account for it.
Detailed changes
This PR:
area_or_point
property attribute toRaster
, that can be set usingset_area_or_point()
(optionally shifts the raster) or usingarea_or_point=...
with default parameters,area_or_point
,_config.py
module with aconfig.ini
file to set global package parameters, relying theconfigparser
package (included as part of core Python), and a relatedtest_config.py
test module,geoutils.config[param] = new_val
,ij2xy()
andcoords()
understand pixel interpretation (onlyxy2ij()
had an implementation until now), now theij2xy()
andxy2ij()
are fully reversible for any pixel interpretation andcoords()
are derived fromij2xy()
for full consistency. Theoffset
argument has become aforce_offset
argument (because coordinates are always defined as upper-left or center depending on interpretation for raster, we should not leave the choice to the user for an offset value except for a "forced" call),interp_points()
to maintain behaviour consistent with coordinates functions,reproject()
andcrop()
if a match-reference raster is used that has a different pixel interpretation than the one being reprojected/cropped,area_or_point
andtags
arguments tofrom_array()
for passing any pixel interpretation or tag metadata to a raster defined from array, and modifiescopy()
accordingly,from_array()
that only changeddata=
into calls tocopy(new_array=)
(completely equivalent and no need to pass on thearea_or_point
),Raster._overloading_check
and_check_cast_array_raster
into a single_cast_numeric_array_raster
function,nodata
bypassed infrom_array()
and other dependent functions #516 in relation to nodata casting.Resolves #508
Resolves #500
Resolves #503
Resolves #127
TODO
_check_cast_raster_array()
and_overloading_check()
into a consistent implementation #508,shift_area_or_point
transformation to all coordinates function still missing it (coords
andij2xy
),area_or_point
when using a match-reference raster to crop/reproject/proximity another raster?shift_area_or_point
to beNone
by default and callconfig["shift_area_or_point"]
,interp_points
functionality,set_area_or_point()
,crop()
,Issues for another PR
Making a documentation page on pixel interpretation, opened #523
The issues #516 and #517 need to be addressed for consistent output, and will require additional modifications of the merged casting function
_cast_numeric_array_raster
.