Skip to content

Commit

Permalink
Define 'nchannels' and 'channel' for 'GeoTIFFImage'
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv committed Nov 19, 2024
1 parent 4a03e94 commit a4add52
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/GeoTIFF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using StaticArrays: SVector, SMatrix, SA
using FixedPointNumbers: Fixed, Normed

import TiffImages
import TiffImages: nchannels, channel

include("geokeys.jl")
include("metadata.jl")
Expand Down
18 changes: 16 additions & 2 deletions src/image.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,31 @@ end
"""
GeoTIFF.tiff(geotiff)
TIFF image of a `geotiff` image.
TIFF image of the `geotiff` image.
"""
tiff(geotiff::GeoTIFFImage) = geotiff.tiff

"""
GeoTIFF.metadata(geotiff)
GeoTIFF metadata of a `geotiff` image.
GeoTIFF metadata of the `geotiff` image.
"""
metadata(geotiff::GeoTIFFImage) = geotiff.metadata

"""
GeoTIFF.nchannels(geotiff)
Number of channels of the `geotiff` image.
"""
nchannels(geotiff::GeoTIFFImage) = nchannels(geotiff.tiff)

"""
GeoTIFF.channel(geotiff, i)
`i`'th channel of the `geotiff` image.
"""
channel(geotiff::GeoTIFFImage, i) = mappedarray(c -> channel(c, i), geotiff.tiff)

# AbstractArray interface
Base.size(geotiff::GeoTIFFImage) = size(geotiff.tiff)
Base.getindex(geotiff::GeoTIFFImage, i...) = getindex(geotiff.tiff, i...)
Expand Down
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ savedir = mktempdir()
geotiff[1, 1] = color
@test geotiff[1, 1] == color
@test IndexStyle(geotiff) === IndexCartesian()

# multi-channel image
file = joinpath(savedir, "multi.tiff")
channel1 = rand(10, 10)
channel2 = rand(10, 10)
channel3 = rand(10, 10)
channel4 = rand(10, 10)
GeoTIFF.save(file, channel1, channel2, channel3, channel4)
geotiff = GeoTIFF.load(file)
@test eltype(geotiff) <: TiffImages.WidePixel
@test GeoTIFF.nchannels(geotiff) == 4
@test GeoTIFF.channel(geotiff, 1) == channel1
@test GeoTIFF.channel(geotiff, 2) == channel2
@test GeoTIFF.channel(geotiff, 3) == channel3
@test GeoTIFF.channel(geotiff, 4) == channel4
end

@testset "save" begin
Expand Down

0 comments on commit a4add52

Please sign in to comment.