Skip to content

VRT writer maps 64-bit integer rasters to wrong dtype #1833

@brendancol

Description

@brendancol

Describe the bug

`write_vrt` in `xrspatial/geotiff/_vrt.py` emits the wrong `dataType` for 64-bit integer source rasters. The dtype lookup at line 1366-1368 has no entry for `bps=64`:

```python
elif sf == 2:
vrt_dtype_name = {8: 'Int8', 16: 'Int16', 32: 'Int32'}.get(bps, 'Int32')
else:
vrt_dtype_name = {8: 'Byte', 16: 'UInt16', 32: 'UInt32'}.get(bps, 'Byte')
```

Signed 64-bit falls back to `Int32` and unsigned 64-bit falls back to `Byte`. The VRT reader has explicit `Int64` and `UInt64` support (`_vrt.py:183-184`), so the writer is the only side that drops the precision.

Reproduce

Write a uint64 raster via `to_geotiff(da, "out.vrt")`. The emitted VRT declares `dataType="Byte"` and reading it back returns uint8 with values truncated to 255.

Expected behavior

64-bit integer rasters should round-trip through VRT without dtype loss. Signed 64-bit should emit `Int64` and unsigned 64-bit should emit `UInt64`.

Fix

Add `64: 'Int64'` to the signed branch and `64: 'UInt64'` to the unsigned branch of the lookup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions