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

Fixes the geotiff open #191

Merged
merged 5 commits into from
May 13, 2023
Merged
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 Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SpeciesDistributionToolkit"
uuid = "72b53823-5c0b-4575-ad0e-8e97227ad13b"
authors = ["Timothée Poisot <timothee.poisot@umontreal.ca>"]
version = "0.0.6"
version = "0.0.7"

[deps]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
Expand Down
21 changes: 11 additions & 10 deletions src/io/geotiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ function _read_geotiff(
driver::String = "GTiff",
compress::String = "LZW",
) where {LT <: SimpleSDMLayer}
@assert driver ∈ keys(ArchGDAL.listdrivers()) ||
throw(ArgumentError("Not a valid driver."))

@assert driver ∈ keys(ArchGDAL.listdrivers()) || throw(ArgumentError("Not a valid driver."))

try
ArchGDAL.read(file) do stuff
wkt = ArchGDAL.importPROJ4(ArchGDAL.getproj(stuff))
Expand Down Expand Up @@ -143,11 +143,11 @@ function _write_geotiff(
file::AbstractString,
layer::SimpleSDMPredictor{T};
nodata::T = convert(T, -9999),
driver::String = "COG",
compress="LZW"
driver::String = "GTiff",
compress = "LZW",
) where {T <: Number}

@assert driver ∈ keys(ArchGDAL.listdrivers()) || throw(ArgumentError("Not a valid driver."))
@assert driver ∈ keys(ArchGDAL.listdrivers()) ||
throw(ArgumentError("Not a valid driver."))
#@assert compress ∈ keys(ArchGDAL.listcompress()) || throw(ArgumentError("Not a valid compression."))

array_t = _prepare_layer_for_burnin(layer, nodata)
Expand Down Expand Up @@ -187,6 +187,7 @@ function _write_geotiff(
options = ["COMPRESS=$compress"],
)
end
isfile(prefix) && rm(prefix)
return file
end

Expand Down Expand Up @@ -214,11 +215,10 @@ function _write_geotiff(
layers::Vector{SimpleSDMPredictor{T}};
nodata::T = convert(T, -9999),
driver::String = "GTiff",
compress::String = "LZW"
compress::String = "LZW",
) where {T <: Number}


@assert driver ∈ keys(ArchGDAL.listdrivers()) || throw(ArgumentError("Not a valid driver."))
@assert driver ∈ keys(ArchGDAL.listdrivers()) ||
throw(ArgumentError("Not a valid driver."))
# to be uncommented once ths getcompressions fcn exists
#@assert compress ∈ keys(ArchGDAL.listcompress()) || throw(ArgumentError("Not a valid compression."))

Expand Down Expand Up @@ -262,6 +262,7 @@ function _write_geotiff(
options = ["COMPRESS=$compress"],
)
end
isfile(prefix) && rm(prefix)
return file
end

Expand Down
12 changes: 11 additions & 1 deletion test/01_integration_read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ layer2 = SpeciesDistributionToolkit._read_geotiff(f, SimpleSDMPredictor)
@test typeof(layer2) <: SimpleSDMPredictor
@test all(values(layer) .== values(layer2))

end
# Write the data
f = tempname() * ".tiff" # This is important because the save function checks extensions
SpeciesDistributionToolkit.save(f, [layer]; nodata = typemax(D))
@test isfile(f)

# Read the data
layer2 = SimpleSDMPredictor(f)
@test typeof(layer2) <: SimpleSDMPredictor
@test all(values(layer) .== values(layer2))

end