Working with Digital Elevation Models (DEM)

Learn how to access and analyze elevation data and generate contour lines for your areas of interest.

Prerequisites: Before starting this tutorial, make sure you have:
  • An ObservEarth API key
  • Created at least one Area of Interest (AOI)
If you haven't done these steps yet, check out our Authentication and Areas of Interest tutorials first.

Accessing Elevation Data

Get Elevation Data

To retrieve elevation data for your area of interest:

API Type
POST
Endpoint
https://observearth.com/api/dem/
Request Body
{
  "geometry_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "format": "png",
  "colormap": "greys"
}
Request Parameters
Parameter Type Required Description
geometry_id UUID Yes UUID of your Area of Interest
format string No Output format (png, tif), default is png
colormap string No Color palette for visualization (e.g., "greys")
Note: The DEM data is sourced from COP-DEM-GLO-30 (Copernicus Digital Elevation Model).
Code Example
import requests
import json
from PIL import Image
from io import BytesIO

api_key = "your_api_key_here"
url = "https://observearth.com/api/dem/"

payload = {
    "geometry_id": "123e4567-e89b-12d3-a456-426614174000",
    "format": "png",
    "colormap": "terrain"
}

headers = {
    "X-API-Key": api_key,
    "Content-Type": "application/json"
}

response = requests.post(url, headers=headers, data=json.dumps(payload))

if response.status_code == 200:
    if payload["format"] == "png":
        # Save and display the image
        with open("elevation.png", "wb") as f:
            f.write(response.content)
        
        # Display the image
        img = Image.open(BytesIO(response.content))
        img.show()
        print("Elevation image saved as elevation.png")
    else:
        # Save as GeoTIFF
        with open("elevation.tif", "wb") as f:
            f.write(response.content)
        print("Elevation data saved as elevation.tif")
else:
    print(f"Error: {response.status_code}")
    print(response.text)

Generating Contour Lines

Get Contour Lines

Contour lines connect points of equal elevation and are useful for visualizing terrain:

API Type
GET
Endpoint
https://observearth.com/api/contours/

[Image: Contour lines overlaid on a satellite image]

Contour lines overlaid on a satellite image showing terrain features.

[Image: 3D visualization with contour lines]

3D visualization with contour lines enhancing terrain perception.

Query Parameters
Parameter Type Required Description
geometry_id UUID Yes UUID of your Area of Interest
interval number No Contour interval in meters, default is 50
format string No Output format (geojson, shapefile), default is geojson

Next Steps