With another application

The plugin is a standard QGIS Server plugin: any application that can send an HTTP request to QGIS Server can use it (OpenLayers, Leaflet, MapLibre, a mobile application, a script…).

First requests

QGIS Server needs the project, with MAP= (unless it is set by QGIS_PROJECT_FILE):

# Elevation layers of the project
curl "https://example.org/qgis/?MAP=/srv/projects/site.qgs&SERVICE=PROFILE&REQUEST=GetElevationLayers"

# Profile along a 2-segment line in Lambert-93, on two layers
curl "https://example.org/qgis/?MAP=/srv/projects/site.qgs&SERVICE=PROFILE&REQUEST=GetElevationProfile&LAYERS=mnt_d609de4c,copernicus_glo30&CRS=EPSG:2154&GEOMETRY=652000,6862000;653500,6862000;654000,6863000"

The details of the parameters and answers are in Requests and answers.

In JavaScript

GEOMETRY can be long: the requests are also accepted as POST, with the parameters in an application/x-www-form-urlencoded body.

const response = await fetch('https://example.org/qgis/', {
  method: 'POST',
  body: new URLSearchParams({
    MAP: '/srv/projects/site.qgs',
    SERVICE: 'PROFILE',
    REQUEST: 'GetElevationProfile',
    LAYERS: 'mnt_d609de4c',
    CRS: 'EPSG:3857',
    // OpenLayers LineString coordinates [[x, y], ...] -> "x1,y1;x2,y2;..."
    GEOMETRY: line.getCoordinates().map((c) => c.join(',')).join(';'),
  }),
});
const data = await response.json();
if (!response.ok) {
  throw new Error(data.message);
}
// data.x: distances in metres; data.profiles[0].y: elevations (null = no value)
// -> draw them with Chart.js, Plotly, D3…

Several layers in several times

SAMPLES sets the number of points: for the same line, the same number gives exactly the same points. A client can thus request the project layers first (fast), then Copernicus (slower) with SAMPLES = number of points of the first answer, and superpose the curves.

The project layers are shown first; Copernicus follows, computed at the same points

The project layers are shown first; Copernicus follows, computed at the same points.

Good to know from a browser

  • CORS: if the page is not served from the same domain as QGIS Server, the web server in front of QGIS Server (nginx, Apache) must send the Access-Control-Allow-Origin header. The plugin does not add it.

  • Rights: they apply only if an access control filter is registered in QGIS Server. Without one, every elevation layer of the project is readable by anyone who can reach QGIS Server (see Security and rights).

  • Copernicus: every profile in a new area makes QGIS Server download data. On a public server, keep ELEVATIONPROFILE_MAX_SAMPLES reasonable, or disable the source.