oslew docs
Console
Menu

Elevation and rasters

A raster is a value on a grid: height above sea level, a forecast temperature, anything measured everywhere rather than at places. Two routes read them. /v1/elevation reads the terrain; /v1/raster reads any layer by name, including the terrain, and adds a time axis for the layers that have one. Both answer at one point or at evenly spaced samples along a path.

A point outside the elevation tiles answers elevation_m: null; see below.

Elevation at a point

curl
curl -G "https://api.oslew.com/v1/elevation" \
  -H "Authorization: Bearer $GEO_API_KEY" \
  --data-urlencode 'at=19.4326,-99.1332'
Python
from oslew import Client

# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")

answer = client.elevation(at="19.4326,-99.1332")
TypeScript
import { Client } from "@oslew/client";

// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });

const answer = await client.elevation({ at: "19.4326,-99.1332" });
Response
HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 299
ratelimit-reset: 1

{
  "results": [
    {
      "lat": 19.4326,
      "lon": -99.1332,
      "elevation_m": 2228.8455999999974,
      "resolution_m": 30
    }
  ],
  "provenance": {
    "name": "copernicus-dem-glo-30",
    "release": "2022-05",
    "license": "Copernicus DEM licence (attribution: © DLR e.V. 2010-2014 and © Airbus Defence and Space GmbH 2014-2018 provided under COPERNICUS by the European Union and ESA)"
  },
  "took_us": 3
}

A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.

elevation_m is interpolated bilinearly between the four grid samples around the point. The grid is stored to the whole metre, so the decimals are the interpolation's, not extra precision: the Zócalo is 2,229 m up, give or take what the model gets wrong. resolution_m is the spacing of the grid that answered — per point, because a path can cross from one elevation layer into another.

What the number is, exactly, matters more than its decimals:

  • A surface, not the ground. The Copernicus GLO-30 DEM is a surface model made from radar: over a forest it is the height of the canopy, over a city the height of what the satellite saw, roofs included. In open country that is the ground; in a dense block or a forest it can be tens of metres above it.
  • Above the geoid, not the ellipsoid. Heights are relative to the EGM2008 geoid — roughly mean sea level. A height above the WGS84 ellipsoid, which is what satellite positioning computes before a geoid model is applied, differs from it by tens of metres in most places, so compare like with like.
  • Nothing is an answer. A point outside every elevation tile, or on a sample the source marks as no-data, comes back with elevation_m and resolution_m both null, in a200. Only a deployment with no elevation layer at all refuses, with no elevation layer loaded.

Along a path

curl
curl -G "https://api.oslew.com/v1/elevation" \
  -H "Authorization: Bearer $GEO_API_KEY" \
  --data-urlencode 'path=19.4326,-99.1332;19.2086,-99.2586' \
  --data-urlencode 'samples=8'
Python
from oslew import Client

# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")

answer = client.elevation(path="19.4326,-99.1332;19.2086,-99.2586", samples=8)
TypeScript
import { Client } from "@oslew/client";

// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });

const answer = await client.elevation({ path: "19.4326,-99.1332;19.2086,-99.2586", samples: 8 });
Response
HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 298
ratelimit-reset: 1

{
  "results": [
    {
      "lat": 19.4326,
      "lon": -99.1332,
      "elevation_m": 2228.8455999999974,
      "resolution_m": 30
    },
    {
      "lat": 19.4006,
      "lon": -99.15111428571429,
      "elevation_m": 2234.058342857149,
      "resolution_m": 30
    },
    {
      "lat": 19.3686,
      "lon": -99.16902857142857,
      "elevation_m": 2251.4623999999963,
      "resolution_m": 30
    },
    {
      "lat": 19.3366,
      "lon": -99.18694285714285,
      "elevation_m": 2280.097314285677,
      "resolution_m": 30
    },
    {
      "lat": 19.3046,
      "lon": -99.20485714285715,
      "elevation_m": 2369.012571428547,
      "resolution_m": 30
    },
    {
      "lat": 19.2726,
      "lon": -99.22277142857143,
      "elevation_m": 2661.419999999993,
      "resolution_m": 30
    },
    {
      "lat": 19.2406,
      "lon": -99.24068571428572,
      "elevation_m": 2940.979257142865,
      "resolution_m": 30
    },
    {
      "lat": 19.2086,
      "lon": -99.2586,
      "elevation_m": 3863.2535999999523,
      "resolution_m": 30
    }
  ],
  "provenance": {
    "name": "copernicus-dem-glo-30",
    "release": "2022-05",
    "license": "Copernicus DEM licence (attribution: © DLR e.V. 2010-2014 and © Airbus Defence and Space GmbH 2014-2018 provided under COPERNICUS by the European Union and ESA)"
  },
  "took_us": 1205
}

A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.

ParameterDefaultIs
at—lat,lon: one point.
path—lat,lon;lat,lon;…: a polyline of at least two points.
samples32How many points to answer along path, clamped to 2–512. Ignored with at.

Give exactly one of at and path; both or neither is a 400, exactly one of at or path. A path of one point is a path needs at least two points.

The samples are spaced evenly by great-circle length along the whole polyline: the first is the path's first point, the last is its last, and the rest are length ÷ (samples − 1) apart. The vertices in between are followed but not themselves sampled, unless a sample happens to land on one. Above, eight samples over the 28 km from the Zócalo to the mountains south-west of the city are 4 km apart, and climb from 2,229 m to 3,863 m. The answer does not carry the distance along the path, because it is arithmetic you can do: sample i isi × length ÷ (samples − 1) from the start.

The grid is 30 m, so samples closer together than that add nothing the model knows, and samples much further apart miss what lies between them. 512 samples over 10 km are 20 m apart and see everything the model does; over 100 km they are 196 m apart, and a ridge, a cutting or a bridge narrower than that can fall between two. For a long path, ask in pieces.

A profile along a route

A route's geometry is already a path: [lat, lon] pairs, both ends included. It is also often thousands of vertices at full precision, and a path travels in the URL. Many proxies and load balancers refuse a request line over about 8 KB, which — with each separator URL-encoded — is roughly 350 points at five decimals. So thin the line first. Douglas–Peucker with a 10 m tolerance keeps the shape to well inside one grid cell and usually removes most of the vertices of a road, which is long straight runs:

Python
import math
from oslew import Client

client = Client(base_url="https://api.oslew.com")

def simplify(pts, tolerance_m=10.0):
    """Douglas–Peucker on [lat, lon] pairs, in metres on a local flat projection."""
    if len(pts) < 3:
        return pts
    kx = 111_320 * math.cos(math.radians(pts[0][0]))
    xy = [(lon * kx, lat * 110_540) for lat, lon in pts]
    keep = [False] * len(pts)
    keep[0] = keep[-1] = True
    stack = [(0, len(pts) - 1)]
    while stack:
        a, b = stack.pop()
        (ax, ay), (bx, by) = xy[a], xy[b]
        norm = math.hypot(bx - ax, by - ay) or 1e-9
        worst, at = 0.0, None
        for i in range(a + 1, b):
            d = abs((by - ay) * (xy[i][0] - ax) - (bx - ax) * (xy[i][1] - ay)) / norm
            if d > worst:
                worst, at = d, i
        if at is not None and worst > tolerance_m:
            keep[at] = True
            stack += [(a, at), (at, b)]
    return [p for p, kept in zip(pts, keep) if kept]

def haversine_m(a, b):
    la1, lo1, la2, lo2 = map(math.radians, (*a, *b))
    h = math.sin((la2 - la1) / 2) ** 2 + math.cos(la1) * math.cos(la2) * math.sin((lo2 - lo1) / 2) ** 2
    return 2 * 6_371_008.8 * math.asin(math.sqrt(h))

route = client.route("19.4326,-99.1332", "19.3467,-99.1617", profile="cycling")
line = simplify(route["geometry"])
path = ";".join(f"{lat:.5f},{lon:.5f}" for lat, lon in line)

samples = 128
heights = [r["elevation_m"] for r in client.elevation(path=path, samples=samples)["results"]]
length = sum(haversine_m(a, b) for a, b in zip(line, line[1:]))
spacing = length / (samples - 1)                      # metres between samples

climb = sum(max(0.0, b - a) for a, b in zip(heights, heights[1:]) if a is not None and b is not None)
print(f"{length / 1000:.1f} km, {climb:.0f} m of climbing, a sample every {spacing:.0f} m")
TypeScript
import { Client } from "@oslew/client";

const client = new Client({ baseUrl: "https://api.oslew.com" });
type LatLon = [number, number];

/** Douglas–Peucker on [lat, lon] pairs, in metres on a local flat projection. */
function simplify(pts: LatLon[], toleranceM = 10): LatLon[] {
  if (pts.length < 3) return pts;
  const kx = 111_320 * Math.cos((pts[0][0] * Math.PI) / 180);
  const xy = pts.map(([lat, lon]) => [lon * kx, lat * 110_540]);
  const keep = pts.map((_, i) => i === 0 || i === pts.length - 1);
  const stack: [number, number][] = [[0, pts.length - 1]];
  while (stack.length) {
    const [a, b] = stack.pop()!;
    const [[ax, ay], [bx, by]] = [xy[a], xy[b]];
    const norm = Math.hypot(bx - ax, by - ay) || 1e-9;
    let worst = 0, at = -1;
    for (let i = a + 1; i < b; i++) {
      const d = Math.abs((by - ay) * (xy[i][0] - ax) - (bx - ax) * (xy[i][1] - ay)) / norm;
      if (d > worst) [worst, at] = [d, i];
    }
    if (at >= 0 && worst > toleranceM) {
      keep[at] = true;
      stack.push([a, at], [at, b]);
    }
  }
  return pts.filter((_, i) => keep[i]);
}

function haversineM([la1, lo1]: LatLon, [la2, lo2]: LatLon): number {
  const r = Math.PI / 180;
  const h = Math.sin(((la2 - la1) * r) / 2) ** 2 + Math.cos(la1 * r) * Math.cos(la2 * r) * Math.sin(((lo2 - lo1) * r) / 2) ** 2;
  return 2 * 6_371_008.8 * Math.asin(Math.sqrt(h));
}

const route = await client.route("19.4326,-99.1332", "19.3467,-99.1617", { profile: "cycling" });
const line = simplify(route.geometry as LatLon[]);
const path = line.map(([lat, lon]) => lat.toFixed(5) + "," + lon.toFixed(5)).join(";");

const samples = 128;
const heights = (await client.elevation({ path, samples })).results.map((r) => r.elevation_m);
const length = line.slice(1).reduce((sum, p, i) => sum + haversineM(line[i], p), 0);
const spacing = length / (samples - 1); // metres between samples

let climb = 0;
for (let i = 1; i < heights.length; i++) {
  const [a, b] = [heights[i - 1], heights[i]];
  if (a != null && b != null && b > a) climb += b - a;
}

The length is measured over the path you sent, because that is the line the samples are spaced along; the route's own distance_m is the road's, and differs by what the thinning straightened. The climb is a sum over a surface model, so trees and buildings beside the road add to it: on a real ride, ignore rises of a metre or two, or smooth the profile first. The route and the profile are two products — routing and platform — so the key's plan needs both; see products and plans.

Any named raster

/v1/raster reads a layer by the name it was loaded under, with the same at,path and samples as elevation, plus a time for the layers that change over time. A name that is not loaded is refused, and the refusal lists what is:

Response
HTTP/1.1 400 Bad Request
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 296
ratelimit-reset: 1

{
  "error": "no raster layer `solar_ghi`; loaded: elevation, ecmwf_10u, ecmwf_10v, ecmwf_2t, ecmwf_msl, ecmwf_tp"
}

A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.

That list is the deployment's, not the API's: a layer is whatever was ingested under a name — solar irradiance, land cover, a population surface — and the error is the way to find out. The names are exact. The loaded layers above are the terrain and five forecast fields:

Layerunitsresolution_mStored to
elevationm30the metre
ecmwf_2t — 2 m temperatureK27,8300.01 K
ecmwf_10u, ecmwf_10v — 10 m wind, eastward and northwardm/s27,8300.01 m/s
ecmwf_tp — total precipitation since the run beganm27,8300.01 mm
ecmwf_msl — mean-sea-level pressurePa27,830the pascal

The answer names the layer, its units and its resolution_m once, and each point carrieslat, lon and a value — null outside the layer's coverage.provenance is null when no point had data. Asking for layer=elevation here reads the same terrain as /v1/elevation; the only difference is that elevation's answer names the field elevation_m and gives the resolution per point.

Layers with a time axis

A forecast field holds one grid per valid time. time (unix seconds, default now) picks the instant, and the value is linear in time between the two valid times either side of it — named in between — as well as bilinear in space. For a layer without a time axis, time is ignored, andtime and between are null in the answer.

curl
curl -G "https://api.oslew.com/v1/raster" \
  -H "Authorization: Bearer $GEO_API_KEY" \
  --data-urlencode 'layer=ecmwf_2t' \
  --data-urlencode 'at=19.4326,-99.1332' \
  --data-urlencode 'time=1795132800'
Python
from oslew import Client

# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")

answer = client.raster("ecmwf_2t", time=1795132800, at="19.4326,-99.1332")
TypeScript
import { Client } from "@oslew/client";

// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });

const answer = await client.raster("ecmwf_2t", { time: 1795132800, at: "19.4326,-99.1332" });
Response
HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 297
ratelimit-reset: 1

{
  "layer": "ecmwf_2t",
  "units": "K",
  "resolution_m": 27830,
  "time": 1795132800,
  "between": [
    1795132800,
    1795132800
  ],
  "results": [
    {
      "lat": 19.4326,
      "lon": -99.1332,
      "value": 289.96362847999995
    }
  ],
  "provenance": {
    "name": "ecmwf-open-data",
    "release": "2026111906",
    "license": "CC-BY-4.0"
  },
  "took_us": 80
}

A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.

Here the instant is itself a valid time, 18 hours into the run, so both ends of between are that step and 289.96 K (16.8 °C) is the step's own value at that point, interpolated only in space. An instant between two steps is a weighted average of the two. Two consequences of interpolating in a straight line:

  • Between widely spaced steps, the daily cycle is lost. A line from a 06:00 value to an 18:00 value passes under the afternoon maximum rather than through it. The spacing of the steps is inbetween; judge the answer by it.
  • Outside the axis there is no forecast, and no error either. Exactly on a step, both ends ofbetween are that step. Before the first step or after the last, the answer is the nearest step's value and between is that step twice — so a time a week out quietly answers with the last step's value. Check it:
Python
answer = client.raster("ecmwf_2t", at="19.4326,-99.1332", time=t)
lo, hi = answer["between"]
if lo == hi != t:
    ...  # outside the forecast: this is the nearest step's value, not a forecast for t

A forecast is data that is overwritten. The layer holds one model run at a time, and a new run replaces the whole field; provenance.release names the run — 2026111906 is the 06 UTC run of 19 November 2026. The same instant asked for after a new run can answer differently, which is the forecast improving; if you cache answers, key them by release. How the fields turn into weather — °C, wind speed and direction, rain over an interval — is in weather and air quality.

For everything at a point at once — every raster layer's value there, beside the administrative areas and the nearest road — see everything at a point.

Endpoints

GET/v1/elevationplatform

Elevation at a point, or sampled evenly along a path.

GET/v1/rasterplatform

Any named raster layer (solar irradiance, land cover, elevation) at a point or sampled evenly along a path.