Skip to content

Design Proposal: handle nodata in raster-dem #1142

@Kanahiro

Description

@Kanahiro

Design Proposal: handle nodata in raster-dem

Motivation

In Japan, an encoding called "Numerical PNG Tile" is used by the government to distribute dem tiles. Many developers utilize it to use DEM data in WebGIS.

https://maps.gsi.go.jp/development/demtile.html

specification: https://maps.gsi.go.jp/development/demtile.html

This encoding is not available as is in MapLibre GL JS because it has two problem so I have to workaround by using addProtocol to modify tile contents to fit to encodings TerrainRGB or Terrarium but as it is not the best way in terms of performance.

My workaround: https://github.com/mug-jp/maplibre-gl-gsi-terrain

Problem1: nodata

This encoding has "no-data" - rgb (128, 0, 0) is treated as nodata and any height value is not defined.
It is good to set height=0 to pixels which has the nodata in ordinary cases. So, I think it is nice to set nodataRgb and nodataValue in raster-dem source.

It may be useful in other encodings when original data has pixels with no-data and they have specific rgb value.

Problem2: not "monotonically increasing"

The encoding is NOT "monotonically increasing" - it means that when red value is bigger than 2^23, we have to subtract 2^24 from value.

Image

I don't have a good solution I can think so, then I don't propose it in this issue.
However I have tried to handle this by adding heightRange to clamp values into the range. I mean if a value is larger than maximum value, substract value toward minimum (like overflow in programming).

https://github.com/Kanahiro/maplibre-gl-js/blob/1beaf562e3d617f35e51d6c2e9bfa2212840a6e0/test/examples/rasterdem-custom-encoding.html#L51

Proposed Change

  • add nodataRgb and nodataHeight parameters to raster-dem source.

API Modifications

 {
    type: "raster-dem",
    tiles: ["https://cyberjapandata.gsi.go.jp/xyz/dem_png/{z}/{x}/{y}.png"],
    tileSize: 256,
    maxzoom: 14,
    encoding: "custom",
    redFactor: 655.36,
    greenFactor: 2.56,
    blueFactor: 0.01,
    nodataRgb: [128, 0, 0], // added
    nodataHeight: 0, // added
}

// means pixles with rgb=128,0,0 are treated as height = 0

https://github.com/Kanahiro/maplibre-gl-js/blob/1beaf562e3d617f35e51d6c2e9bfa2212840a6e0/test/examples/rasterdem-custom-encoding.html#L52

Migration Plan and Compatibility

none

Rejected Alternatives

none

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