Skip to content

Commit

Permalink
Switch from missing to nothing
Browse files Browse the repository at this point in the history
This is for two reasons:

1. The nodata value isn't meant to be used as a "sentinel value" in the raster output. If ArchGDAL wants to provide a convenience function for returning `Array{Union{T, Missing}}`, the treatment of missing data should be based on the appropriate use of `getmaskband()` (https://trac.osgeo.org/gdal/wiki/rfc15_nodatabitmask for details).

2. Even if ArchGDAL does provide a convenience function for returning `Array{Union{T, Missing}}`, the proper place for using `missing` values is in the array being constructed, and not the value being returned from `getnodatavalue(band)`.
  • Loading branch information
yeesian committed Jun 21, 2021
1 parent 317272f commit 800bf2c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/raster/rasterband.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ end
Fetch the no data value for this band.
If there is no out of data value, `missing` will be returned instead. The no
If there is no out of data value, `nothing` will be returned instead. The no
data value for a band is generally a special marker value used to mark pixels
that are not valid data. Such pixels should generally not be displayed, nor
contribute to analysis operations.
### Returns
the nodata value for this band or `missing`.
the nodata value for this band or `nothing`.
"""
function getnodatavalue(band::AbstractRasterBand)::Union{Float64,Missing}
function getnodatavalue(band::AbstractRasterBand)::Union{Float64,Nothing}
# ### Parameters
# * `pbSuccess` pointer to a boolean to use to indicate if a value is
# actually associated with this layer. May be `NULL` (default).
Expand All @@ -193,7 +193,7 @@ function getnodatavalue(band::AbstractRasterBand)::Union{Float64,Missing}
return if Bool(hasnodatavalue[])
nodatavalue
else
missing
nothing
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const AG = ArchGDAL;

@test sprint(print, AG.getband(dataset, 1)) == """
[GA_ReadOnly] Band 1 (Red): 2048 x 1024 (UInt8)
blocksize: 256×256, nodata: missing, units: 1.0px + 0.0
blocksize: 256×256, nodata: nothing, units: 1.0px + 0.0
overviews: (0) 1024x512 (1) 512x256 (2) 256x128
(3) 128x64 (4) 64x32 (5) 32x16
(6) 16x8 """
Expand Down
4 changes: 2 additions & 2 deletions test/test_ospy_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ const AG = ArchGDAL;
outband = AG.getband(outDS, 1)
@test sprint(print, outband) == """
[GA_Update] Band 1 (Undefined): 5665 x 5033 (Float32)
blocksize: 5665×1, nodata: missing, units: 1.0px + 0.0
blocksize: 5665×1, nodata: nothing, units: 1.0px + 0.0
overviews: """
AG.setnodatavalue!(outband, -99)
# georeference the image and set the projection
Expand Down Expand Up @@ -484,7 +484,7 @@ const AG = ArchGDAL;
bandout = AG.getband(dsout, 1)
@test sprint(print, bandout) == """
[GA_Update] Band 1 (Undefined): 4500 x 3000 (UInt8)
blocksize: 4500×1, nodata: missing, units: 1.0px + 0.0
blocksize: 4500×1, nodata: nothing, units: 1.0px + 0.0
overviews: """

# set the geotransform and projection on the output
Expand Down
20 changes: 10 additions & 10 deletions test/test_rasterband.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ const AG = ArchGDAL;
AG.setscale!(rb, 1)
@test AG.getscale(rb) 1

@test ismissing(AG.getnodatavalue(rb))
@test isnothing(AG.getnodatavalue(rb))
AG.setnodatavalue!(rb, -100)
@test AG.getnodatavalue(rb) -100
AG.deletenodatavalue!(rb)
@test ismissing(AG.getnodatavalue(rb))
@test isnothing(AG.getnodatavalue(rb))

AG.copy(dataset) do dest
destband = AG.getband(dest, 1)
AG.copywholeraster!(rb, destband)
@test sprint(print, destband) == """
[GA_Update] Band 1 (Gray): 100 x 100 (UInt8)
blocksize: 100×81, nodata: missing, units: 1.0px + 0.0
blocksize: 100×81, nodata: nothing, units: 1.0px + 0.0
overviews: """
@test AG.noverview(destband) == 0
AG.buildoverviews!(dest, Cint[2, 4, 8])
@test AG.noverview(destband) == 3
@test sprint(print, destband) == """
[GA_Update] Band 1 (Gray): 100 x 100 (UInt8)
blocksize: 100×81, nodata: missing, units: 1.0px + 0.0
blocksize: 100×81, nodata: nothing, units: 1.0px + 0.0
overviews: (0) 50x50 (1) 25x25 (2) 13x13
"""
@test AG.getcolorinterp(destband) == AG.GCI_GrayIndex
Expand All @@ -70,25 +70,25 @@ const AG = ArchGDAL;

@test sprint(print, AG.sampleoverview(destband, 100)) == """
[GA_Update] Band 1 (Gray): 13 x 13 (UInt8)
blocksize: 128×128, nodata: missing, units: 1.0px + 0.0
blocksize: 128×128, nodata: nothing, units: 1.0px + 0.0
overviews: """
@test sprint(print, AG.sampleoverview(destband, 200)) == """
[GA_Update] Band 1 (Gray): 25 x 25 (UInt8)
blocksize: 128×128, nodata: missing, units: 1.0px + 0.0
blocksize: 128×128, nodata: nothing, units: 1.0px + 0.0
overviews: """
@test sprint(print, AG.sampleoverview(destband, 500)) == """
[GA_Update] Band 1 (Gray): 25 x 25 (UInt8)
blocksize: 128×128, nodata: missing, units: 1.0px + 0.0
blocksize: 128×128, nodata: nothing, units: 1.0px + 0.0
overviews: """
AG.sampleoverview(destband, 1000) do result
@test sprint(print, result) == """
[GA_Update] Band 1 (Gray): 50 x 50 (UInt8)
blocksize: 128×128, nodata: missing, units: 1.0px + 0.0
blocksize: 128×128, nodata: nothing, units: 1.0px + 0.0
overviews: """
end
@test sprint(print, AG.getmaskband(destband)) == """
[GA_ReadOnly] Band 0 (Undefined): 100 x 100 (UInt8)
blocksize: 100×81, nodata: missing, units: 1.0px + 0.0
blocksize: 100×81, nodata: nothing, units: 1.0px + 0.0
overviews: """
@test AG.maskflags(destband) == 1
@test AG.maskflaginfo(rb) == (
Expand All @@ -101,7 +101,7 @@ const AG = ArchGDAL;
AG.getmaskband(destband) do maskband
@test sprint(print, maskband) == """
[GA_Update] Band 1 (Gray): 100 x 100 (UInt8)
blocksize: 100×81, nodata: missing, units: 1.0px + 0.0
blocksize: 100×81, nodata: nothing, units: 1.0px + 0.0
overviews: """
end
@test AG.maskflags(destband) == 3
Expand Down

0 comments on commit 800bf2c

Please sign in to comment.