Raster query
The Raster Query API allows users to request information related to a point location from one or more Koordinates grid or raster datasets.
The endpoint depends on the Koordinates site you’re using. On koordinates.com it’s:
https://koordinates.com/services/query/v1/rasterQuery raster values at a pointThe raster query API returns in JSON:
content-type: application/vnd.koordinates.rasterQuery+jsonFormats can be specified via URL. For example: https://koordinates.com/services/query/v1/raster.json
They can also be specified using the HTTP Accept header with the appropriate content-type against the base URL. For example: application/vnd.koordinates.rasterQuery-1+json.
By default, all responses use the newest format. While we try very hard to prevent backwards-incompatible breaks, please note that it may happen in future.
If you’re using the URL endpoint (for example, raster.json) you can pass a &v=1 parameter to specify version 1. Note that the current version is 1.
Compression
Section titled “Compression”Add a request header with Accept-Encoding: gzip to get compressed results. This dramatically reduces the size of the response and will speed up your API requests.
Parameters
Section titled “Parameters”- key: Required, unless you send your key in an
Authorization: key YOUR_API_KEYheader instead. Your Koordinates API key. - layer: Required. The layer ID to get results from. The layer numbers can be found in the URL for a layer (eg. https://koordinates.com/layer/1132-land-environments-new-zealand-len… is layer 1132). Repeat this parameter to query more than one layer, up to a maximum of 10 layers.
- x: Required. Longitude of the point you want to query, in decimal degrees (WGS84/EPSG:4326). The valid range is -180 to 180.
- y: Required. Latitude of the point you want to query, in decimal degrees (WGS84/EPSG:4326). The valid range is -90 to 90.
- include_tiles: Optional (default false). If true, the response also includes information about the source raster tiles at the point, such as when each tile was last updated.
- callback: Optional. If supplied, will use the JSONP format with a callback of the given name. In addition, most error responses will be returned as 200-success codes, with a string error message.
Response
Section titled “Response”Each queried layer returns a status and, when the point is inside the layer, a bands list with one value per band. For example, a point in the NZ 8m DEM returns:
{"rasterQuery": {"layers": {"51768": {"type": "Raster", "status": "ok", "bands": [{"value": 19.746280670166016}]}}, "location": [174.78, -36.85]}}A point outside the layer returns "status": "outside-extent" with no bands. Layers that aren’t grid or raster layers are left out of the response.
Getting an image for a point
Section titled “Getting an image for a point”The raster query returns information about a point, not image data. To get a PNG image, request a tile from the XYZ tile service:
https://tiles-cdn.koordinates.com/services;key=YOUR_API_KEY/tiles/v4/layer=LAYER_ID/EPSG:3857/Z/X/Y.pngYour API key needs the tiles scope, which keys created with Data access have. Z is the zoom level, and X and Y are the standard web map (slippy map) tile column and row that contain your longitude and latitude at that zoom level. If you use the WMTS capabilities template instead, TileMatrixSet is EPSG:3857, TileMatrix is Z, TileCol is X and TileRow is Y.
This Python function converts a longitude and latitude to tile numbers:
import math
def tile(lon, lat, z): n = 2 ** z lat = max(min(lat, 85.05112878), -85.05112878) # web maps stop at this latitude x = min(int((lon + 180) / 360 * n), n - 1) y = min(int((1 - math.asinh(math.tan(math.radians(lat))) / math.pi) / 2 * n), n - 1) return max(x, 0), max(y, 0)
tile(174.781986658826, -36.802424493619, 15) # (32293, 19991)