Generate COGs from AWS Terrain Tiles
With the ever-increasing volume of open data out there, we’re always looking for ways to make it more accessible and useful. The AWS Terrain Tiles dataset is an amazing open data resource created by Mapzen. According to its creators, it “consists of thousands of digital elevation model (DEM) data sources at various resolutions from around the globe, merged together and split into billions of map tiles”. Terrain tiles are available on AWS S3 for anyone to access.
DEM data has a huge variety of applications. These include topographic mapping (think contour lines and hillshading), 3D visualization, flood and drainage modeling, hazard mapping, or extracting geomorphic attributes like slope and aspect.
Obtaining DEM data in the past would require you to identify a source covering your area of interest. Then there would be a clunky download process, often involving several files which would then be followed by a manual merge and clip process to get the data to match your area of interest.
AWS Terrain Tiles have global coverage so they can provide a solution to this issue. But there’s a lack of simple tools for accessing the data. As part of a hack day at Sparkgeo we decided to build a tool to solve this problem.
The result is Terradactile. Please note Terradactile is currently in its alpha phase and is a work in progress. Let us know if you experience any issues.
Terradactile is a web map application which generates DEM and hillshade COGs (Cloud Optimized GeoTIFFs) based on AWS Terrain Tile data.
Our goal with this app was to make it as simple as possible for the user to go from drawing an area of interest to displaying and/or downloading elevation data.
1. Draw an area of interest
2. Fetch and process the elevation tiles
When the user clicks the “Generate DEM and hillshade” button, a request is sent to the Terradactile API, which triggers an AWS Lamba function. The function is able to make use of spatial Python modules that are normally too large to be included in Lambdas, by leveraging two GeoLambda layers, found here. The lambda function has several responsibilities, including:
- listing and fetching necessary elevation tiles
- mosaicking tiles into a continuous DEM
- clipping the tiles to the area of interest
- computing a hillshade layer from the DEM
- converting both the DEM and hillshade to COG format
- creating an 8-bit DEM for display in the browser
- saving these layers to AWS S3 storage.
The response from the API is simply a path to the S3 storage folder, containing three outputs:
- mosaic.tif: the DEM, containing real elevation values
- mosaic_display.tif: the DEM, fit into 8-bit values (0-255)
- hillshade.tif: the hillshade layer. You can find the code for the Lambda function and full serverless deployment in our repo here.
3. Display the result within Terradactile
Because the layers are stored in COG format, we can use a dynamic tiler to fetch and display only the necessary imagery tiles, directly from S3 storage. We make use of titiler in this application.
4. Download the DEM and/or hillshade
We’d love to hear how you’re using Terradactile.
If you like the app we’ve built here, want to utilize more open data, or want to work with COGs, Sparkgeo can help.
You can find Terradactile here