Creating 3D Terrain Maps from GeoTIFF Files with Three.js

EmailTwitterLinkedInFacebookWhatsAppShare

Introduction

Visualizing Digital Elevation Models (DEMs) in 3D is an engaging way to explore terrain data. In this tutorial, we’ll create an interactive 3D terrain map using Three.js and a GeoTIFF file. GeoTIFF is a popular format for storing geospatial raster data, such as elevation.

By the end of this tutorial, you’ll know how to:

  • Load GeoTIFF files.
  • Parse elevation data.
  • Render 3D terrain using Three.js.
  • Apply grayscale or color shading for terrain representation.

Access Complete Source Code and Data here.

Demo

Step 1: Setting Up the Project

1.1. Prerequisites

Ensure you have the following installed:

1.2. Project Structure

Create a folder with the following structure:

1.3. Install Dependencies

Initialize a Node.js project and install required libraries:


Step 2: Writing HTML

Create an index.html file to serve as the project entry point. It will host the terrain container.


Step 3: Loading and Parsing GeoTIFF

In the main.js file, use the GeoTIFF.js library to load and extract raster data.


Step 4: Generating the 3D Terrain

We’ll use a PlaneGeometry mesh for the terrain and manipulate its vertex positions to reflect elevation values.


Step 5: Adding Colors to the Terrain

You can generate a colored texture or keep it grayscale. In this example, we create a grayscale representation.


Step 6: Setting Up Three.js

Initialize the scene, camera, renderer, and controls.



Step 7: Viewing the Terrain

Start a local server using Node.js and open index.html in your browser to view the interactive 3D terrain.

Open http://localhost:5173 in your browser.


Conclusion

This tutorial showcased how to render a 3D terrain from GeoTIFF data using Three.js. You can further enhance this by adding:

  • More advanced lighting and material effects.
  • Interactive features like point picking.
  • Displaying additional data layers.

Feel free to share your terrain visualizations or suggest improvements!

I hope this tutorial will create a good foundation for you. If you want tutorials on another GIS topic or you have any queries, please send an mail at contact@spatial-dev.guru.

Leave a ReplyCancel reply

Discover more from Spatial Dev Guru

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from Spatial Dev Guru

Subscribe now to keep reading and get access to the full archive.

Continue reading