How to convert a Rasters.Raster{UInt8,2} to a Raster{Float32,2}?

Hello, as from the title, how can I convert a Rasters.Raster{UInt8,2} to a Raster{Float32,2} ?
I have tried with convert(Raster{Float64,2},myraster) but this method is not defined…

Use broadcast: Float32.(myraster)

1 Like

Thank you, it “almost” works, but I still have the problem to update also the missingval and if I try to do it directly (e.g. myraster_converted_to_float32.missingval = 0.0f0) I got the error that the Raster struct is not mutable…

replace_missing first may help. Or rebuild(A; missingval=x)

Maybe we could apply the broadcast to it automatically…

1 Like

Just to follow up: convert should work as it works on regular arrays. At the same time we can convert the missingval.

I’ll fix this in DimensionalData.jl and Rasters.jl.

You should also be able to do this with any other AbstractDimArray like a YAXArray

1 Like