Skip to content
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

[WIP] [Option 1] Handle TIFFs with more than one image #17

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/GeoTIFF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module GeoTIFF

using TiffImages: AbstractTIFF, DenseTaggedImage, WidePixel
using TiffImages: AbstractTIFF, DenseTaggedImage, StridedTaggedImage, WidePixel
using ColorTypes: Colorant, Gray
using MappedArrays: mappedarray
using StaticArrays: SVector, SMatrix, SA
Expand Down
11 changes: 9 additions & 2 deletions src/image.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ to get the metadata and the image with corrected axes, respectively.
* The [`GeoTIFF.image`](@ref) function is necessary because
the GeoTIFF format swaps the order of the image axes;
"""
struct GeoTIFFImage{T,N,I<:AbstractTIFF{T,N}} <: AbstractArray{T,N}
struct GeoTIFFImage{T,I<:AbstractMatrix{T}} <: AbstractMatrix{T}
tiff::I
metadata::Metadata
end
Expand Down Expand Up @@ -59,4 +59,11 @@ channel(geotiff::GeoTIFFImage, i) = mappedarray(c -> channel(c, i), image(geotif
Base.size(geotiff::GeoTIFFImage) = size(geotiff.tiff)
Base.getindex(geotiff::GeoTIFFImage, i...) = getindex(geotiff.tiff, i...)
Base.setindex!(geotiff::GeoTIFFImage, v, i...) = setindex!(geotiff.tiff, v, i...)
Base.IndexStyle(::Type{GeoTIFFImage{T,N,I}}) where {T,N,I} = IndexStyle(I)
Base.IndexStyle(::Type{GeoTIFFImage{T,I}}) where {T,I} = IndexStyle(I)

struct GeoTIFFImages{I<:GeoTIFFImage} <: AbstractVector{I}
geotiffs::Vector{I}
end

Base.size(geotiff::GeoTIFFImages) = size(geotiff.geotiffs)
Base.getindex(geotiff::GeoTIFFImages, i) = getindex(geotiff.geotiffs, i)
15 changes: 11 additions & 4 deletions src/load.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@ The keyword arguments are forward to the `TiffImages.load` function.
* [`ModelTransformation`](@ref) with `A` as identity matrix and `b` as vector of zeros.
"""
function load(fname; kwargs...)
geotiff(img, ifd) = GeoTIFFImage(img, _getmetadata(ifd))
tiff = TiffImages.load(fname; kwargs...)
metadata = _getmetadata(tiff)
GeoTIFFImage(tiff, metadata)
ifds = TiffImages.ifds(tiff)
if tiff isa StridedTaggedImage
GeoTIFFImages(geotiff.(tiff, ifds))
elseif ndims(tiff) == 3
imgs = eachslice(tiff, dims=3)
GeoTIFFImages(geotiff.(imgs, ifds))
else
geotiff(tiff, ifds)
end
end

# -----------------
# HELPER FUNCTIONS
# -----------------

function _getmetadata(tiff)
ifd = TiffImages.ifds(tiff)
function _getmetadata(ifd)
geokeydirectory = _gettag(ifd, GeoKeyDirectoryTag, GeoKeyDirectory)
geodoubleparams = _gettag(ifd, GeoDoubleParamsTag, GeoDoubleParams)
geoasciiparams = _gettag(ifd, GeoAsciiParamsTag, GeoAsciiParams)
Expand Down
Loading