Skip to content

to_geotiff has no way to set LERC max_z_error #1510

@brendancol

Description

@brendancol

Problem

to_geotiff(..., compression='lerc') always calls lerc_compress with max_z_error=0.0 (lossless). LERC's main draw is that you can trade a small per-pixel error budget for big size savings on float data, and there is currently no public way to set that budget.

xrspatial/geotiff/_writer.py:401-404, 464-467, 1106-1109 all call lerc_compress(strip_data, ..., samples=samples, dtype=dtype) without forwarding a max_z_error argument, so it falls through to the function default of 0.0 in _compression.py:1018-1020.

Repro

```python
import numpy as np, xarray as xr, os
from xrspatial.geotiff import to_geotiff

data = xr.DataArray(np.random.rand(1024, 1024).astype(np.float32))
to_geotiff(data, '/tmp/lossless.tif', compression='lerc')
to_geotiff(data, '/tmp/lossy.tif', compression='lerc') # no way to ask for lossy

print(os.path.getsize('/tmp/lossless.tif'),
os.path.getsize('/tmp/lossy.tif')) # identical
```

Suggested fix

Add max_z_error: float = 0.0 to to_geotiff and forward it through _write_stripped, _prepare_tile, the streaming writer, COG, and VRT paths into lerc_compress. Validate that max_z_error == 0 (or raise) when the selected compression is not LERC, so callers don't silently get the value ignored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions