Rasters.jl
Rasters.jl copied to clipboard
`typeof(missingval)` should be a subtype of `eltype`
Consider
ras = Raster(rand(Int32, X(25:1:30), Y(25:1:30)), missingval=-1.5)
Is allowing the type of missingval not being a subtype of the eltype useful for anything?
The reason I came across this is that it took me ages to figure out what was wrong here:
julia> ras = Raster(rand(Int32, X(25:1:30), Y(25:1:30)), missingval=-1)
6×6 Raster{Int32,2} with dimensions:
X Sampled{Int64} 25:1:30 ForwardOrdered Regular Points,
Y Sampled{Int64} 25:1:30 ForwardOrdered Regular Points
extent: Extent(X = (25, 30), Y = (25, 30))
missingval: -1
parent:
25 26 27 28 29 30
25 -1577965140 -930532794 -1069034332 -1869000944 -876112444 -1896541373
26 -2119450237 2112008256 -574130295 234237348 295379253 -1608673699
27 479548452 1163904508 -1753155508 -779730610 -508137957 -545965278
28 -518000084 -1234244315 2027127016 -1383270083 1182867062 1198615452
29 -575807158 253215731 731658899 -1561393151 2005117126 1945068211
30 -1836660204 -1824357014 -734002877 853304731 1129518778 -1924398571
julia> write("/tmp/band.tif", ras, force=true)
ERROR: GDALError (CE_Failure, code 1):
GetNoDataValue() should be called instead
Stacktrace:
...
which can be fixed with
julia> ras = Raster(rand(Int32, X(25:1:30), Y(25:1:30)), missingval=Int32(-1));
julia> write("/tmp/band.tif", ras, force=true)
Anyways, should there be a conversion missingval = convert(eltyp(data), missingval)?
Its probably not useful for anything.
And yes that could trigger the wrong gdal methods (it has specific methods for different types, which is kinda crazy)
Lets fix it to match the array eltype
This is enforced now