Terrain Viewer

QGIS Plugin (plan)

A QGIS plugin with the app's sidebar, in two steps - a panel that writes tile service layers, then the modes computed in Python with numpy.

Today QGIS gets the app's modes through the tile service: /qgis.qgz is a project with every mode as an XYZ layer, configured as a view was. A layer's settings live in its address, and QGIS has no control bound to an XYZ address's parameters: changing a ramp or a radius means editing the layer's source URL. A plugin is the way to have controls. Two steps, the first cheap.

Step 1: a panel that writes tile service layers (done)

Written on 2026-11-23, in qgis-plugin/. Checked headless in QGIS 4.2 and 3.44 LTR against a local tile service: the panel builds, a share link opens, the layers are valid and draw.

A dock panel laid out as the app's sidebar: the same groups (Elevation Hypso, Terrain Analysis, Relief Visualization, Hillshade, Lighting Effects, Overlays), each mode a checkbox with its opacity and settings (ramp, range, radius, method) behind a gear button, a terrain source picker, the keys, and the address of a tile service.

  • Each checked mode is a layer of the project: an XYZ layer whose address the panel writes (/tiles/{z}/{x}/{y}.png?modes=<mode>&<its settings>), as /qgis.qgz does, in a "Terrain Viewer" group with the app's panel groups, stacked as the map stacks them. A changed setting rewrites that layer's address and refreshes it; only the settings that differ from the app's defaults go into it. Opacity and blending stay QGIS layer settings (the tiles are asked opaque, the shading modes multiplied; see the QGIS section of the tile service page).
  • The overlays (contours, iso-line, mound candidates, plane slicer, graticule) are raster layers as the app draws them, and on demand also vector tile layers (.pbf), styled by the plugin in the mode's colour.
  • The lists come from the service: /sources for the terrain sources, /colorramps for the ramps, and /modes, added for the plugin: the panel's groups and, for each mode, its form, whether it is shading, its opacity parameter and its settings (the app's URL parameters, with type, allowed values and default, from the generated URL reference). So a new mode or parameter in the app reaches the plugin without a plugin release.
  • "Open from link": paste a share link, get its layers. /modes?<the link's query> answers what the view switches on, the opacities, the parameters every layer keeps and the camera (the reading /qgis.qgz does).
  • A saved project reopens as it was: on Connect, the panel reads its layers' addresses back into its checkboxes and settings.
  • Pure Python on QGIS's own API, no dependency. It needs a reachable tile service: a local one (cd tile-server && pnpm start) or a hosted one.

Install

cd qgis-plugin && python make_zip.py   # dist/terrain_viewer-0.1.0.zip

In QGIS: Plugins, Manage and Install Plugins, Install from ZIP, then the Terrain Viewer button in the toolbar (or Web, Terrain Viewer). Not yet on plugins.qgis.org.

Step 2: the modes computed in QGIS

The same panel with no tile service: the modes computed in Python, on the elevation the plugin reads.

  • Reading: GDAL reads the tiles and nothing else. A Terrarium or Terrain-RGB pyramid through GDAL's WMS/TMS driver (the XML of gdalTileSource in lib/terrain-tile-spec.ts), a COG or VRT directly, a raw WMS through GDAL's WMS driver. Decoding the RGB packing into metres is numpy (the formulas of lib/elevation-encoding.ts). The sources only the app's protocols read (LERC, quantized mesh, GEM-15's cells, a difference) need their own reader or stay on step 1.
  • Computing: numpy, not gdaldem: the app's modes are its own (LRM, sky view factor, openness, matcap, Phong, the mound detector, the eigen-based ones), and the point is that QGIS shows what the app shows. Each lib/*-protocol.ts is a kernel over an elevation grid with a margin, which ports to numpy array code: slope, aspect, curvature, TPI, TRI and roughness in a few lines each; sky view factor and openness as the app's ray sweeps (vectorised per direction); matcap and Phong as the shaders' formulas per pixel; the colour ramps from lib/color-ramps.ts.
  • Delivery: a QGIS raster layer per mode, computed for the canvas extent at the canvas resolution and recomputed on pan and zoom (debounced, in a background task), or written to a GeoTIFF on request. Optionally a Processing provider, so each mode is also an algorithm for models and batch runs.
  • Checking: the port is checked against the app tile by tile, as tile-server/compare-engines.mjs checks the direct engine against the browser: same tiles, a table of differences.
  • Keeping in step: two implementations of each mode drift. The comparison above runs in CI on a fixed set of tiles, so a change to a protocol that the Python port does not follow fails a check.

Weeks of work, mode by mode; step 1 stays useful as the fallback for any mode not ported yet.

On this page