Limited Error Raster Compression
Actively maintained. Last release 4 weeks ago, commits in 11 of the last 26 weeks. A safe choice.
pip install pylercpylerc is the LERC Python package
LERC is an open-source raster format which supports rapid encoding and decoding for any pixel type, with user-set maximum compression error per pixel.
What's new in Lerc 4.2?
Lerc 4.2 adds stricter size limits for improved safety:
- Input data to encode is limited to 2 GB per band.
- Compressed Lerc blob size is limited to 2 GB per band.
- Total compressed Lerc blob size is limited to 4 GB across all bands.
What's new in Lerc 4.0?
Option 1, uses numpy masked array
An encoded image tile (2D, 3D, or 4D), of data type byte to double, can have any value set to invalid. There are new and hopefully easy to use numpy functions to decode from or encode to Lerc. They make use of the numpy masked array.
(result, npmaArr, nDepth, npmaNoData) = decode_ma(lercBlob)
- lercBlob is the compressed Lerc blob as a string buffer or byte array as read in from disk or passed in memory.
- result is 0 for success or an error code for failure.
- npmaArr is the masked numpy array with the data and mask of the same shape.
- nDepth == nValuesPerPixel. E.g., 3 for RGB, or 2 for complex numbers.
- npmaNoData is a 1D masked array of size nBands. It can hold one noData value per band. The caller can usually ignore it as npmaArr has all mask info. It may be useful if the data needs to be Lerc encoded again.
(result, nBytesWritten, lercBlob) = encode_ma(npmaArr, nDepth, maxZErr, nBytesHint, npmaNoData = None)
-
npmaArr is the image tile (2D, 3D, or 4D) to be encoded, as a numpy masked array.
-
nDepth == nValuesPerPixel. E.g., 3 for RGB, or 2 for complex numbers.
-
maxZErr is the max encoding error allowed per value. 0 means lossless.
-
nBytesHint can be
- 0 - compute num bytes needed for output buffer, but do not encode it (faster than encode)
- 1 - do both, compute exact buffer size needed and encode (slower than encode alone)
- N - create buffer of size N and encode, if buffer too small encode will fail.
-
npmaNoData is a 1D masked array of size nBands. It can hold one noData value per band. It can be used as an alternative to masks. It must be used for the so called mixed case of valid and invalid values at the same pixel, only possible for nDepth > 1. In most cases None can be passed. Note Lerc does not take NaN as a noData value here. It is enough to set the data values to NaN and not specify a noData value.