diff --git a/.gitignore b/.gitignore index 64cc5468..8d03c3b8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ Manifest.toml temp/ **/*.properties +local diff --git a/Project.toml b/Project.toml index 44d334c1..2a3d38df 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/io.jl b/src/io.jl index 82b5e92f..c6f52229 100644 --- a/src/io.jl +++ b/src/io.jl @@ -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 +