• Stars
    star
    179
  • Rank 206,397 (Top 5 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Limited Error Raster Compression

LERC - Limited Error Raster Compression

What is LERC?

LERC is an open-source image or raster format which supports rapid encoding and decoding for any pixel type (not just RGB or Byte). Users set the maximum compression error per pixel while encoding, so the precision of the original input image is preserved (within user defined error bounds).

This repository contains a C++ library for both encoding and decoding images. You can also do this directly from Python. And we have decoders for JavaScript and C#.

The LERC C API

Function Description
uint lerc_computeCompressedSize(...) Computes the buffer size that needs to be allocated so the image can be Lerc compressed into that buffer. The size is accurate to the byte. This function is optional. It is faster than lerc_encode(...). It can also be called to decide whether an image or image tile should be encoded by Lerc or another method.
uint lerc_encode(...) Compresses a given image into a pre-allocated buffer. If that buffer is too small, the function fails with the corresponding error code. The function also returns the number of bytes written.
uint lerc_getBlobInfo(...) Looks into a given Lerc byte blob and returns an array with all the header info. From this, the image to be decoded can be allocated and constructed. This function is optional. You don't need to call it if you already know the image properties such as tile size and data type.
uint lerc_getDataRanges(...) Looks into a given Lerc byte blob and returns 2 double arrays with the minimum and maximum values per band and depth. This function is optional. It allows fast access to the data ranges without having to decode the pixels.
uint lerc_decode(...) Uncompresses a given Lerc byte blob into a pre-allocated image. If the data found in the Lerc byte blob does not fit the specified image properties, the function fails with the corresponding error code.
uint lerc_decodeToDouble(...) Uncompresses a given Lerc byte blob into a pre-allocated image of type double independent of the compressed data type. This function was added mainly to be called from other languages such as Python and C#.

To support the case that not all image pixels are valid, a mask image can be passed. It has one byte per pixel, 1 for valid, 0 for invalid.

See the sample program src/LercTest/main.cpp which demonstrates how the above functions are called and used. Also see the two header files in the src/LercLib/include/ folder and the comments in there.

About multiple bands, or multiple values per pixel. This has changed with Lerc version 2.4. Before, you could either store each band into its own Lerc byte blob which allowed you to access / decode each band individually. Lerc also allowed to stack bands together into one single Lerc byte blob. This could be useful if the bands are always used together anyway. Now, since Lerc version 2.4, you can additionally store multiple values per pixel interleaved, meaning an array of values for pixel 1, next array of values for pixel 2, and so forth. We have added a new parameter "nDepth" for this number of values per pixel.

While the above can be used as an "interleave flag" to store multiple raster bands as a 3D array as either [nBands, nRows, nCols] for band interleaved or as [nRows, nCols, nDepth] for pixel interleaved, it also allows to do both at the same time and store a 4D array as [nBands, nRows, nCols, nDepth].

Note that the valid / invalid pixel byte mask is not 4D but limited to [nBands, nRows, nCols]. This mask is per pixel per band. For nDepth > 1 or an array of values per pixel, up to Lerc version 3.0, Lerc assumed all values in that array at that pixel are either valid or invalid. If the values in the innermost array per pixel can be partially valid and invalid, use a predefined noData value or NaN.

To better support this special "mixed" case, we have added new Lerc API functions *_4D() in Lerc version 4.0, see Lerc_c_api.h. These functions allow to pass one noData value per band to the encode_4D() function and can receive it back in the decode_4D() function. This way such data can be compressed with maxZError > 0 or lossy, despite the presence of noData values in the data. Note that Lerc will convert noData values to 0 bytes in the valid / invalid byte mask whenever possible. This also allows now to pass raster data with noData values to the encoder without first creating the valid / invalid byte mask. NoData values can be passed both ways, as noData or as byte mask. Note that on decode Lerc only returns a noData value for the mixed case of valid and invalid values at the same pixel (which can only happen for nDepth > 1). The valid / invalid byte mask remains the preferred way to represent void or noData values.

Remark about NaN. As Lerc supports both integer and floating point data types, and there is no NaN for integer types, Lerc filters out NaN values and replaces them. Preferred it pushes NaN's into the valid / invalid byte mask. For the mixed case, it replaces NaN by the passed noData value. If there is no noData value, encode will fail. Lerc decode won't return any NaN's.

When to use

In image or raster compression, there are two different options:

  • compress an image as much as possible but so it still looks ok (jpeg and relatives). The max coding error per pixel can be large.

  • prioritize control over the max coding error per pixel (elevation, scientific data, medical image data, ...).

In the second case, data is often compressed using lossless methods, such as LZW, gzip, and the like. The compression ratios achieved are often low. On top the encoding is often slow and time consuming.

Lerc allows you to set the max coding error per pixel allowed, called "MaxZError". You can specify any number from 0 (lossless) to a number so large that the decoded image may come out flat.

In a nutshell, if jpeg is good enough for your images, use jpeg. If not, if you would use png instead, or gzip, then you may want to try out Lerc.

How to use

Lerc can be run anywhere without external dependencies. This project includes test samples of how to use LERC directly, currently for C++, Python, JavaScript, and C#. We have added a few small data samples under testData/. There is also a precompiled Windows dll and a Linux .so file under bin/.

How to use without compiling LERC

Check out the Lerc decoders and encoders in OtherLanguages/. You may need to adjust the paths to input or output data and the dll or .so file. Other than that they should just work.

Other download sites

How to compile LERC and the C++ test program

For building the Lerc library on any platform using CMake, use CMakeLists.txt. For the most common platforms you can find alternative project files under build/.

Windows

  • Open build/Windows/MS_VS2022/Lerc.sln with Microsoft Visual Studio.
  • Build and run.

Linux

  • Open build/Linux/CodeBlocks/Lerc/Lerc_so.cbp using the free Code::Blocks IDE for Linux.
  • Build it. Should create libLerc_so.so.
  • Open build/Linux/CodeBlocks/Test/Test.cbp.
  • Build and run.

MacOS

  • Open build/MacOS/Lerc64/Lerc64.xcodeproj with Xcode.
  • Build to create dynamic library.

LERC can also be used as a compression mode for the GDAL image formats GeoTIFF (since GDAL 2.4) and MRF (since GDAL 2.1) via GDAL.

LERC Properties

  • works on any common data type, not just 8 bit: char, byte, short, ushort, int, uint, float, double.

  • works with any given MaxZError or max coding error per pixel.

  • can work with a byte mask that specifies which pixels are valid and which ones are not.

  • is very fast: encoding time is about 20-30 ms per MegaPixel per band, decoding time is about 5 ms per MegaPixel per band.

  • compression is better than most other compression methods for larger bitdepth data (int types larger than 8 bit, float, double).

  • for 8 bit data lossless compression, PNG can be better, but is much slower.

  • in general for lossy compression with MaxZError > 0, the larger the error allowed, the stronger the compression. Compression factors larger than 100x have been reported.

  • this Lerc package can read all (legacy) codec versions of Lerc, such as Lerc1, Lerc2 v1 to v5, and the current Lerc2 v6. It always writes the latest stable version.

The main principle of Lerc and history can be found in doc/MORE.md

Benchmarks

Some benchmarks are in doc/LercBenchmarks_Feb_2016.pdf

Bugs?

The codecs Lerc2 and Lerc1 have been in use for years, bugs in those low level modules are very unlikely. All software updates are tested in Esri software for months before they are uploaded to this repo.

Licensing

Copyright 2015-2022 Esri

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

A copy of the license is available in the repository's LICENSE file.

More Repositories

1

arcgis-python-api

Documentation and samples for ArcGIS API for Python
Python
1,766
star
2

esri-leaflet

A lightweight set of tools for working with ArcGIS services in Leaflet. 🚀
JavaScript
1,551
star
3

wind-js

An demo animation of wind on a Canvas layer in the JSAPI
JavaScript
690
star
4

geometry-api-java

The Esri Geometry API for Java enables developers to write custom applications for analysis of spatial data. This API is used in the Esri GIS Tools for Hadoop and other 3rd-party data processing solutions.
Java
679
star
5

jsapi-resources

A collection of useful resources for developers using the ArcGIS API for JavaScript.
JavaScript
675
star
6

terraformer

A geographic toolkit for dealing with geometry, geography, formats, and building geo databases
JavaScript
673
star
7

arcgis-runtime-samples-android

ArcGIS Runtime SDK for Android Samples
Java
656
star
8

esri.github.io

Esri GitHub landing page
JavaScript
510
star
9

gis-tools-for-hadoop

The GIS Tools for Hadoop are a collection of GIS tools for spatial analysis of big data.
507
star
10

esri-loader

A tiny library to help load ArcGIS API for JavaScript modules in non-Dojo applications
TypeScript
451
star
11

arcgis-js-api

Minified version of the ArcGIS API for JavaScript
SCSS
391
star
12

arcgis-maps-sdk-dotnet-samples

Sample code for ArcGIS Maps SDK for .NET – WPF, WinUI, .NET MAUI
C#
386
star
13

arcgis-osm-editor

ArcGIS Editor for OpenStreetMap is a toolset for GIS users to access and contribute to OpenStreetMap through their Desktop or Server environment.
C#
381
star
14

resource-proxy

Proxy files for DotNet, Java and PHP.
PHP
370
star
15

bootstrap-map-js

A light-weight JS/CSS extension for building awesome mapping apps with Bootstrap and ArcGIS.
HTML
366
star
16

deep-learning-frameworks

Installation support for Deep Learning Frameworks for the ArcGIS System
358
star
17

spatial-framework-for-hadoop

The Spatial Framework for Hadoop allows developers and data scientists to use the Hadoop data processing system for spatial data analysis.
Java
354
star
18

arcgis-rest-js

compact, modular JavaScript wrappers for the ArcGIS REST API
TypeScript
335
star
19

arcgis-runtime-samples-ios

Swift samples demonstrating various capabilities of ArcGIS Runtime SDK for iOS
Swift
322
star
20

react-arcgis

A few components to help you get started using the ArcGIS API for JavaScript and esri-loader with React
TypeScript
314
star
21

i3s-spec

This repository hosts the specification for Scene Layers which are containers for arbitrarily large amounts of geographic data. The delivery and persistence model for Scene Layers, referred to as Indexed 3d Scene Layer (I3S) and Scene Layer Package (SLPK) respectively, are specified.
310
star
22

arcgis-pro-sdk

ArcGIS Pro SDK for Microsoft .NET is the new .NET SDK for the ArcGIS Pro Application.
282
star
23

arcgis-cookbook

Chef cookbooks for ArcGIS
Ruby
274
star
24

developer-support

Proof of concept developer code and samples to help be successful with all ArcGIS developer products (Python, NET, JavaScript, Android…). The repository is designed to be an exchange for sharing coding conventions and wisdom to developers at all skill levels.
C#
258
star
25

calcite-design-system

A monorepo containing the packages for Esri's Calcite Design System
TypeScript
252
star
26

cedar

JavaScript Charts for ArcGIS
Handlebars
250
star
27

arcade-expressions

ArcGIS Arcade expression templates for all supported profiles in the ArcGIS platform.
JavaScript
246
star
28

geoportal-server

Geoportal Server is a standards-based, open source product that enables discovery and use of geospatial resources including data and services.
C#
242
star
29

calcite-maps

A Bootstrap theme for designing, styling and creating modern map apps.
JavaScript
237
star
30

esri-leaflet-geocoder

helpers for using the ArcGIS World Geocoding Service in Leaflet
JavaScript
227
star
31

quickstart-map-js

ArcGIS JavaScript mapping samples to get you started fast.
HTML
218
star
32

angular-esri-map

A collection of directives to help you use Esri maps and services in your Angular applications
JavaScript
213
star
33

arcgis-pro-sdk-community-samples

ArcGIS Pro SDK for Microsoft .NET Framework Community Samples
C#
210
star
34

vitruvio

Vitruvio brings the powerful ArcGIS CityEngine procedural modeling capabilities to Unreal Engine.
C++
204
star
35

awesome-arcgis-developers

A curated list of resources to help you with ArcGIS development, APIs, SDKs, tools, and location services
198
star
36

arcgis-maps-sdk-dotnet-toolkit

Toolkit for ArcGIS Maps SDK for .NET
C#
198
star
37

cityengine-sdk

CityEngine is a 3D city modeling software for urban design, visual effects, and VR/AR production. With its C++ SDK you can create plugins and standalone apps capable to execute CityEngine CGA procedural modeling rules.
197
star
38

ArcREST

python package for REST API (AGS, AGOL, webmap JSON, etc..)
Python
194
star
39

raster-functions

A curated set of lightweight but powerful tools for on-the-fly image processing and raster analysis in ArcGIS.
Python
188
star
40

arcgis-to-geojson-utils

Tools to convert ArcGIS JSON geometries to GeoJSON geometries and vice-versa.
JavaScript
186
star
41

raster-deep-learning

ArcGIS built-in python raster functions for deep learning to get you started fast.
Python
180
star
42

generator-esri-appbuilder-js

Yeoman generator to help customize Esri's WebAppBuilder
JavaScript
179
star
43

public-transit-tools

Tools for working with GTFS public transit data in ArcGIS
Python
159
star
44

geodev-hackerlabs

A place to learn how to build geo apps with the ArcGIS Platform.
HTML
157
star
45

offline-editor-js

ArcGIS JavaScript library for handling offline editing and tiling.
JavaScript
156
star
46

storymap-tour

The Story Map Tour is ideal when you want to present a linear, place-based narrative featuring images or videos.
JavaScript
149
star
47

ago-assistant

A swiss army knife for your ArcGIS Online and Portal for ArcGIS accounts
JavaScript
149
star
48

arcgis-js-cli

CLI to build a template application and widgets using the ArcGIS API for JavaScript
TypeScript
137
star
49

arcgis-viewer-flex

Source code for ArcGIS Viewer for Flex - a great application framework for web applications.
ActionScript
135
star
50

arcgis-webpack-plugin

Webpack plugin for the ArcGIS API for JavaScript
JavaScript
134
star
51

joint-military-symbology-xml

Joint Military Symbology Markup Language is a data encapsulation of MIL-STD-2525D and APP-6(D).
C#
134
star
52

file-geodatabase-api

FileGeodatabaseAPI_1.4 (1.4.0.183) The File Geodatabase C++ API for Windows, MacOS and Linux
131
star
53

solutions-geoprocessing-toolbox

Models, scripts, and tools for use in ArcGIS Desktop and Server to support defense and intelligence workflows.
Python
131
star
54

arcgis-maps-sdk-samples-qt

ArcGIS Maps SDK for Qt Samples
C++
129
star
55

geojson-layer-js

An easy way to load GeoJSON data into your ArcGIS map
JavaScript
126
star
56

geojson-utils

A set of utilities for converting between standard geojson and other json formats
JavaScript
123
star
57

arcobjects-sdk-community-samples

This repo contains the source code samples (.Net c#, .Net vb, and C++) that demonstrate the usage of the ArcObject SDK.
C#
118
star
58

ago-admin-wiki

A collection of code samples, scripts, hacks, tools, and information for ArcGIS Online administrators.
117
star
59

OptimizeRasters

OptimizeRasters is a set of tools for converting raster data to optimized Tiled TIF or MRF files, moving data to cloud storage, and creating Raster Proxies.
HTML
115
star
60

arcgis-maps-sdk-toolkit-qt

ArcGIS Maps SDK for Qt Toolkit
C++
112
star
61

android-gps-test-tool

Test all aspects of Android's location capabilities. Configurable for trying out different scenarios.
Java
111
star
62

calcite-web

Authoritative front-end development resources for Calcite design initiative. Includes extendable base components and styles, as well as a modular and efficient framework for ArcGIS properties.
SCSS
107
star
63

arcgis-maps-sdk-java-samples

ArcGIS Maps SDK for Java samples
Java
106
star
64

arcgis-experience-builder-sdk-resources

ArcGIS Experience Builder samples
TypeScript
105
star
65

arcgis-powershell-dsc

This repository contains scripts, code and samples for automating the install and configuration of ArcGIS (Enterprise and Desktop) using Microsoft Windows PowerShell DSC (Desired State Configuration).
PowerShell
105
star
66

maps-app-android

Your organisations mapping app built with the runtime SDK for android
Java
101
star
67

palladio

Palladio enables the execution of CityEngine CGA rules inside of SideFX Houdini.
C++
100
star
68

storymap-journal

The Story Map Journal is ideal when you want to combine narrative text with maps and other embedded content.
JavaScript
97
star
69

arcgis-maps-sdk-unity-samples

Sample code for the ArcGIS Maps SDK for Unity.
C#
96
star
70

arcgis-appstudio-samples

Collection of samples available in AppStudio for ArcGIS desktop to learn and help build your next app.
QML
96
star
71

storymap-cascade

The Story Map Cascadeâ„  app lets you combine narrative text with maps, images, and multimedia content in an engaging, full-screen scrolling experience.
JavaScript
94
star
72

dojo-theme-flat

Custom flat theme based on Twitter's Bootstrap for Dojo dijits, dgrid, and esri widgets.
CSS
92
star
73

html5-geolocation-tool-js

Mobile ArcGIS API for JavaScript samples for testing various geolocation configurations.
HTML
92
star
74

application-boilerplate-3x-js

Starter application that simplifies the process of building templates for the ArcGIS.com template gallery.
JavaScript
89
star
75

angular-cli-esri-map

Example Angular component for building mapping applications with the ArcGIS API for JavaScript
TypeScript
88
star
76

arcgis-vectortile-style-editor

A simple Vector Tile Style Editor to update the styles of Esri Vector Basemaps
CSS
88
star
77

feedback-js-api-next

Try out the next release of the ArcGIS Maps SDK for JavaScript and share your feedback. Be warned: this release is still in development and is unstable.
86
star
78

geoportal-server-catalog

Esri Geoportal Server is a next generation open-source metadata catalog and editor, based on elasticsearch.
JavaScript
85
star
79

ago-tools

A Python package to assist with administering ArcGIS Online Organizations.
Python
77
star
80

workforce-scripts

A set of scripts to help administer Workforce projects.
Jupyter Notebook
77
star
81

esri-leaflet-doc

Documentation, API Reference and Samples
Handlebars
77
star
82

cordova-plugin-advanced-geolocation

Highly configurable native Android interface to both GPS and NETWORK on-device location providers.
Java
74
star
83

maps-app-javascript

Your organizations maps app built with ArcGIS API for Javascript
TypeScript
73
star
84

terraformer-wkt-parser

Well-Known Text parser for Terraformer
JavaScript
71
star
85

geoprocessing-tools-for-hadoop

The Hadoop GP Toolbox provides tools to exchange features between a Geodatabase and Hadoop and run Hadoop workflow jobs.
Python
71
star
86

dojo-bootstrap-map-js

Samples for how to use the Esri ArcGIS API for JavaScript w/ Bootstap via Dojo-bootstrap
JavaScript
71
star
87

collector-tools

A set of python scripts and geoprocessing tools to automate common tasks and workflows in conjunction with Collector for ArcGIS
Python
71
star
88

public-information-map-template-js

An ArcGIS Online mapping template to showcase social media on a map for disaster response and public information.
JavaScript
69
star
89

geoform-template-js

GeoForm is a configurable template for form based data editing of a Feature Service.
JavaScript
66
star
90

webhooks-samples

Sample receivers, scripts, and workflows to help you get started with Webhooks in ArcGIS Enterprise
Python
66
star
91

react-redux-js4

Boilerplate ArcGIS JS API 4.x app using React and Redux
JavaScript
66
star
92

arcgis-maps-sdk-unreal-engine-samples

Sample code for the ArcGIS Maps SDK for Unreal Engine.
C++
65
star
93

arcgis-maps-sdk-dotnet-demos

Demo applications provided by the ArcGIS Runtime SDK for .NET Team
C#
63
star
94

node-geoservices-adaptor

This is a node.js implementation of the ArcGIS REST API
JavaScript
63
star
95

storymap-series

The Story Map Series lets you present a series of maps via tabs, numbered bullets, or a side accordion.
JavaScript
63
star
96

cluster-layer-js

One example of how to cluster many point features
JavaScript
62
star
97

mdcs-py

MDCS is an acronym for Mosaic Dataset Configuration Script and is the entry point to a collection of Python classes/libraries that could be consumed by a Python client application to complete a given workflow for creating a mosaic dataset, populating it with data, and setting all required/desired parameters.
Python
62
star
98

calcite-ui-icons

A collection of UI icons built by Esri for applications.
JavaScript
61
star
99

nearby-android

ArcGIS Android app to find places nearby and route to the nearest location.
Java
60
star
100

local-government-desktop-addins

A series of ArcGIS Desktop Add-ins used in the ArcGIS for Local Government editing maps.
C#
60
star