-
Notifications
You must be signed in to change notification settings - Fork 27
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
Let getnodatavalue return nothing if there is none #176
Conversation
I fully support this. Currently GeoData.jl throws a warning when it doesnt match the type of the array, but otherwise just assumes its the real nodata value. It would need a breaking version bump. |
If we will deviate from the GDAL behavior here anyway, should we also apply scale and offset if present? https://gdal.org/api/gdalrasterband_cpp.html#classGDALRasterBand_1abf5ddfd58352f8b2f98af8ab48786d9c
|
Well I do agree that returning Applying scaling/offset to the nodata value seems inconsistent if we also don't do it for retrieving actual the band values, which would be a much larger change (and possible interfere with DiskArrays?). Besides, I have encountered only encountered these scaled/offsetted rasters once or twice. |
Ah I did not know about I think it might be good to expose this functionality in ArchGDAL instead, maybe through simple So I would be in favor of closing this one... |
This would be my understanding yes. See the documentation of the flags here: https://gdal.org/doxygen/classGDALRasterBand.html#a181a931c6ecbdd8c84c5478e4aa48aaf
We can do both? We should make users aware of the multiple "nodata" options possible, but I still like this improvement of returning |
Ok, then let's continue with this. I have updated the unit tests. I realized that """
maskflaginfo(band::AbstractRasterBand)
Returns the flags as in `maskflags`(@ref) but unpacks the bit values into a named
tuple with the following fields:
* `all_valid`
* `per_dataset`
* `alpha`
* `nodata`
### Returns
A named tuple with unpacked mask flags
"""
function maskflaginfo(band::AbstractRasterBand)
flags = maskflags(band)
(
all_valid = !iszero(flags & 0x01),
per_dataset = !iszero(flags & 0x02),
alpha = !iszero(flags & 0x04),
nodata = !iszero(flags & 0x08),
)
end An alternative would be to use (BitFlags.jl)[https://github.com/jmert/BitFlags.jl] to get pretty printing for which flags are set. |
Yup! We have for e.g. Lines 142 to 160 in f6f44ca
|
Correct me if I'm wrong, but I think we're following Julia's conventions, while still remaining consistent with GDAL semantics here? I.e. the current codebase is hardcoding a Applying scale and offset, on the other hand, would result in behavior that's different in semantics from GDAL. |
Thanks a lot for the comments from everyone. So we agree, that we should not apply scale_factor and add_offset. I have added the |
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.
I have just one remaining (optional) nit, but LGTM otherwise!
Currently the
getnodatavalue
always returns a value for aRasterBand
, no matter if one is actually defined or not. After applying this change,nothing
would be returned instead if there is no such value defined. I think although this would be breaking, it would enable a more fine-grained control for handling data with unknown content.As an alternative and to not break existing code, one could add a
hasnodatavalue
function instead. I would like to hear other opinions, maybe @rafaqz or @evetion could give a hint how it would affect GeoData.jl and GeoArrays.jl?I would still need to fix the unit tests but wanted to hear some general opinions first.