Display ArchGDAL geotiff raster wants unsigned type?

I wanted to look at this raster with ArchGDAL:

using ArchGDAL
(loaded raster from disk)

julia> e
GDAL Dataset (Driver: GTiff/GeoTIFF)
File(s): 
  /Users/florian.oswald/Downloads/population_fra_2019-07-01_geotiff/population_fra_2019-07-01.tif
  /Users/florian.oswald/Downloads/population_fra_2019-07-01_geotiff/population_fra_2019-07-01.tif.aux.xml

Dataset (width x height): 52928 x 35136 (pixels)
Number of raster bands: 1
  [GA_ReadOnly] Band 1 (Gray): 52928 x 35136 (Float64)

julia> ArchGDAL.imread(e)
ERROR: TypeError: in Normed, in T, expected T<:Unsigned, got Type{Float64}
Stacktrace:
  [1] (::ArchGDAL.var"#112#113")(img::Matrix{Float64})

Geotiff float32 and unsigned are two very different beasts. float32 are grids whilst 1 byte are images. 2 bytes are fuzzy but according to my definition they are grids as well.
Your guy is pretty big, doesn’t look so from size because the file is highly compressed. Don’t know how to deal with it in ArchGDAL but in GMT

using GMT
G = gmtread("population_fra_2019-07-01.tif");

typeof(G)
GMTgrid{Float32, 2}

size(G)
(35136, 52928)

imshow(G)

1 Like

ArchGDAL.imread is meant to read raster images to Julia images (matrix of colors). This raster is not an image but Float64 data in the range 0 to 367.

It is probably better to read the data using ArchGDAL.readraster or ArchGDAL.read, as Float64 data. If you want to plot that data as an image, you can make use of the tools of Images.jl, for instance:

using ImageCore

data = rand(3, 4) .* 367
scaled_data = data ./ 367
Gray.(scaled_data)

image

The error is not great however. It would be appreciated if you could file an issue, referencing this thread, probably we can make it better.