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

Fix InexactError in Read Raster #240

Merged
merged 5 commits into from
Jun 9, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
Manifest.toml
temp/
**/*.properties
local
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
AlgebraicMultigrid = "0.2"
ArchGDAL = "0.3.1"
ArchGDAL = "0.3.1, 0.4.0"
GZip = "0.5.1"
IterativeSolvers = "0.7"
LightGraphs = "1"
Expand Down
23 changes: 17 additions & 6 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,19 +451,30 @@ function read_raster(path::String, T)
# Extract the array
array_t = ArchGDAL.read(band)

# Extract no data value and overwrite with Circuitscape/Omniscape default
nodata_val = convert(eltype(array_t), ArchGDAL.getnodatavalue(band))

array_t[array_t .== nodata_val] .= -9999.0
# This handles UInt tiff rasters that can still have negative NoData values
# Need to convert the NoData value to Int64 in these cases
if eltype(array_t) <: Integer
ras_type = Int64
else
ras_type = eltype(array_t)
end

# Line to handle NaNs in datasets read from tifs
array_t[isnan.(array_t)] .= -9999.0
# Extract no data value, first converting it to the proper type (based on
# the raster). Then, need to convert to T. Weird, yes,
# but it's the only way I could get it to work for all raster types...
nodata_val = convert(T, convert(ras_type, ArchGDAL.getnodatavalue(band)))

# Transpose the array -- ArchGDAL returns a x by y array, need y by x
array = convert(Array{T}, permutedims(array_t, [2, 1]))

array[array .== nodata_val] .= -9999.0

# Line to handle NaNs in datasets read from tifs
array[isnan.(array)] .= -9999.0

# Close connection to dataset
ArchGDAL.destroy(raw)

array, wkt, transform # wkt and transform are needed later for write_raster
end