Skip to content

Commit 1dc8ca8

Browse files
authored
Let getnodatavalue return nothing if there is none (#176)
* getnodatavalue returns nothing if there is none * Update unit tests * Increment version * Add maskflaginfo function * Add maskflaginfo unit test * explicit return
1 parent f6f44ca commit 1dc8ca8

File tree

5 files changed

+52
-18
lines changed

5 files changed

+52
-18
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uuid = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
33
keywords = ["GDAL", "IO"]
44
license = "MIT"
55
desc = "A high level API for GDAL - Geospatial Data Abstraction Library"
6-
version = "0.5.3"
6+
version = "0.6.0"
77

88
[deps]
99
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/raster/rasterband.jl

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,25 @@ end
164164
165165
Fetch the no data value for this band.
166166
167-
If there is no out of data value, an out of range value will generally be
168-
returned. The no data value for a band is generally a special marker value
167+
If there is no out of data value, `nothing` will be
168+
returned instead. The no data value for a band is generally a special marker value
169169
used to mark pixels that are not valid data. Such pixels should generally
170170
not be displayed, nor contribute to analysis operations.
171171
172172
### Returns
173-
the nodata value for this band.
173+
the nodata value for this band or `nothing`.
174174
"""
175175
function getnodatavalue(band::AbstractRasterBand)
176176
# ### Parameters
177177
# * `pbSuccess` pointer to a boolean to use to indicate if a value is
178178
# actually associated with this layer. May be `NULL` (default).
179-
return GDAL.gdalgetrasternodatavalue(band.ptr, C_NULL)
179+
hasnodatavalue = Ref(Cint(0))
180+
nodatavalue = GDAL.gdalgetrasternodatavalue(band.ptr, hasnodatavalue)
181+
if Bool(hasnodatavalue[])
182+
return nodatavalue
183+
else
184+
return nothing
185+
end
180186
end
181187

182188
"""
@@ -582,6 +588,32 @@ a valid mask band.
582588
"""
583589
maskflags(band::AbstractRasterBand) = GDAL.gdalgetmaskflags(band.ptr)
584590

591+
592+
"""
593+
maskflaginfo(band::AbstractRasterBand)
594+
595+
Returns the flags as in `maskflags`(@ref) but unpacks the bit values into a named
596+
tuple with the following fields:
597+
598+
* `all_valid`
599+
* `per_dataset`
600+
* `alpha`
601+
* `nodata`
602+
603+
### Returns
604+
605+
A named tuple with unpacked mask flags
606+
"""
607+
function maskflaginfo(band::AbstractRasterBand)
608+
flags = maskflags(band)
609+
return (
610+
all_valid = !iszero(flags & 0x01),
611+
per_dataset = !iszero(flags & 0x02),
612+
alpha = !iszero(flags & 0x04),
613+
nodata = !iszero(flags & 0x08),
614+
)
615+
end
616+
585617
"""
586618
createmaskband!(band::AbstractRasterBand, nflags::Integer)
587619

test/test_display.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import ArchGDAL; const AG = ArchGDAL
5858

5959
@test sprint(print, AG.getband(dataset, 1)) == """
6060
[GA_ReadOnly] Band 1 (Red): 2048 x 1024 (UInt8)
61-
blocksize: 256×256, nodata: -1.0e10, units: 1.0px + 0.0
61+
blocksize: 256×256, nodata: nothing, units: 1.0px + 0.0
6262
overviews: (0) 1024x512 (1) 512x256 (2) 256x128
6363
(3) 128x64 (4) 64x32 (5) 32x16
6464
(6) 16x8 """

test/test_ospy_examples.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ AG.read("ospy/data4/aster.img") do ds
360360
outband = AG.getband(outDS, 1)
361361
@test sprint(print, outband) == """
362362
[GA_Update] Band 1 (Undefined): 5665 x 5033 (Float32)
363-
blocksize: 5665×1, nodata: 0.0, units: 1.0px + 0.0
363+
blocksize: 5665×1, nodata: nothing, units: 1.0px + 0.0
364364
overviews: """
365365
AG.setnodatavalue!(outband, -99)
366366
# georeference the image and set the projection
@@ -448,7 +448,7 @@ end end end end
448448
bandout = AG.getband(dsout, 1)
449449
@test sprint(print, bandout) == """
450450
[GA_Update] Band 1 (Undefined): 4500 x 3000 (UInt8)
451-
blocksize: 4500×1, nodata: 0.0, units: 1.0px + 0.0
451+
blocksize: 4500×1, nodata: nothing, units: 1.0px + 0.0
452452
overviews: """
453453

454454
# set the geotransform and projection on the output

test/test_rasterband.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ import ArchGDAL; const AG = ArchGDAL
4141
AG.setscale!(rb, 1)
4242
@test AG.getscale(rb) 1
4343

44-
@test AG.getnodatavalue(rb) -1e10
44+
@test AG.getnodatavalue(rb) === nothing
4545
AG.setnodatavalue!(rb, -100)
4646
@test AG.getnodatavalue(rb) -100
4747
AG.deletenodatavalue!(rb)
48-
@test AG.getnodatavalue(rb) -1e10
48+
@test AG.getnodatavalue(rb) === nothing
4949

5050
AG.copy(dataset) do dest
5151
destband = AG.getband(dest, 1)
5252
AG.copywholeraster!(rb, destband)
5353
@test sprint(print, destband) == """
5454
[GA_Update] Band 1 (Gray): 100 x 100 (UInt8)
55-
blocksize: 100×81, nodata: -1.0e10, units: 1.0px + 0.0
55+
blocksize: 100×81, nodata: nothing, units: 1.0px + 0.0
5656
overviews: """
5757
@test AG.noverview(destband) == 0
5858
AG.buildoverviews!(dest, Cint[2, 4, 8])
5959
@test AG.noverview(destband) == 3
6060
@test sprint(print, destband) == """
6161
[GA_Update] Band 1 (Gray): 100 x 100 (UInt8)
62-
blocksize: 100×81, nodata: -1.0e10, units: 1.0px + 0.0
62+
blocksize: 100×81, nodata: nothing, units: 1.0px + 0.0
6363
overviews: (0) 50x50 (1) 25x25 (2) 13x13
6464
"""
6565
@test AG.getcolorinterp(destband) == GDAL.GCI_GrayIndex
@@ -68,35 +68,37 @@ import ArchGDAL; const AG = ArchGDAL
6868

6969
@test sprint(print, AG.sampleoverview(destband, 100)) == """
7070
[GA_Update] Band 1 (Gray): 13 x 13 (UInt8)
71-
blocksize: 128×128, nodata: -1.0e10, units: 1.0px + 0.0
71+
blocksize: 128×128, nodata: nothing, units: 1.0px + 0.0
7272
overviews: """
7373
@test sprint(print, AG.sampleoverview(destband, 200)) == """
7474
[GA_Update] Band 1 (Gray): 25 x 25 (UInt8)
75-
blocksize: 128×128, nodata: -1.0e10, units: 1.0px + 0.0
75+
blocksize: 128×128, nodata: nothing, units: 1.0px + 0.0
7676
overviews: """
7777
@test sprint(print, AG.sampleoverview(destband, 500)) == """
7878
[GA_Update] Band 1 (Gray): 25 x 25 (UInt8)
79-
blocksize: 128×128, nodata: -1.0e10, units: 1.0px + 0.0
79+
blocksize: 128×128, nodata: nothing, units: 1.0px + 0.0
8080
overviews: """
8181
AG.sampleoverview(destband, 1000) do result
8282
@test sprint(print, result) == """
8383
[GA_Update] Band 1 (Gray): 50 x 50 (UInt8)
84-
blocksize: 128×128, nodata: -1.0e10, units: 1.0px + 0.0
84+
blocksize: 128×128, nodata: nothing, units: 1.0px + 0.0
8585
overviews: """
8686
end
8787
@test sprint(print, AG.getmaskband(destband)) == """
8888
[GA_ReadOnly] Band 0 (Undefined): 100 x 100 (UInt8)
89-
blocksize: 100×81, nodata: -1.0e10, units: 1.0px + 0.0
89+
blocksize: 100×81, nodata: nothing, units: 1.0px + 0.0
9090
overviews: """
9191
@test AG.maskflags(destband) == 1
92+
@test AG.maskflaginfo(rb) == (all_valid = true, per_dataset = false, alpha = false, nodata = false)
9293
AG.createmaskband!(destband, 3)
9394
AG.getmaskband(destband) do maskband
9495
@test sprint(print, maskband) == """
9596
[GA_Update] Band 1 (Gray): 100 x 100 (UInt8)
96-
blocksize: 100×81, nodata: -1.0e10, units: 1.0px + 0.0
97+
blocksize: 100×81, nodata: nothing, units: 1.0px + 0.0
9798
overviews: """
9899
end
99100
@test AG.maskflags(destband) == 3
101+
@test AG.maskflaginfo(destband) == (all_valid = true, per_dataset = true, alpha = false, nodata = false)
100102
AG.fillraster!(destband, 3)
101103
AG.setcategorynames!(destband, ["foo","bar"])
102104
@test AG.getcategorynames(destband) == ["foo", "bar"]

0 commit comments

Comments
 (0)