Skip to content

Values get clamped to typemax and typemin on write instead of InexactError #487

@tiemvanderdeure

Description

@tiemvanderdeure

Values that cannot be represented by the eltype of a data silently clamped to typemin and typemax, where I would expect an InexactError as with other array types.

This might be intentional/documented behaviour? I ran into this through a Raster where that is not really obvious.

MWE

using ArchGDAL
out = "/tmp/jl_u5ihOBCFCl.tif"
width, height = 100, 100
data = fill(-1, width, height)  # (rows, cols)
driver = ArchGDAL.getdriver("GTiff")
ArchGDAL.create(out; driver, width, height, nbands = 1, dtype= UInt8) do ds
    band = ArchGDAL.getband(ds, 1)
    ArchGDAL.write!(band, data)
end

# similarly
ds = ArchGDAL.readraster(out; flags = ArchGDAL.OF_UPDATE)
ds[1] === 0x00
ds[1,2] = 1e10 # no error
ds[1,2] === typemax(UInt8) # value is clamped to max
close(ds)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions