11 KiB
11 KiB
(English Version)
User Manual: Elevation Tool
1. Introduction
Elevation Tool is a desktop application designed to retrieve elevation data (altitude) for specific geographic coordinates (latitude and longitude) on the Earth's surface. It utilizes NASADEM DEM (Digital Elevation Model) data, an improved version of SRTM data provided by NASA.
The application allows you to:
- Get the elevation for a single point.
- Automatically download the necessary DEM data "tiles" and their corresponding preview ("browse") images from remote servers.
- Maintain a local cache of downloaded data for fast offline access and to reduce repeated downloads.
- Pre-download data for an entire geographic area.
- Visualize browse images of individual tiles or a mosaic of the downloaded area.
- Visualize the elevation data of a single tile as an interactive 3D plot.
2. Prerequisites and Installation
Before using the application, ensure you have the following:
- Python: A recent version of Python 3 installed on your system.
- Python Libraries: Install the required libraries using
pip:pip install requests rasterio Pillow matplotlib numpy netrc opencv-pythonrequests: For downloading data from the internet.rasterio: For reading DEM data (HGT files).Pillow: For processing preview images.matplotlib: For displaying 2D images and 3D plots.numpy: A fundamental dependency forrasterioandmatplotlib.netrc: For handling authentication (often already present).opencv-python: (Currently unused in the final version, but potentially useful for future 2D processing).
- NASA Earthdata Login Account: NASADEM data requires a free account. Register at: https://urs.earthdata.nasa.gov/users/new
.netrcFile for Authentication: To allow the application to download protected data, you must create a file named.netrcin your system's home directory:- Location:
- Windows:
C:\Users\YourUsername\.netrc - Linux/macOS:
/home/yourusername/.netrc(or/Users/yourusername/.netrc)
- Windows:
- Content (use a plain text editor):
Replacemachine urs.earthdata.nasa.gov login YOUR_EARTHDATA_USERNAME password YOUR_EARTHDATA_PASSWORDYOUR_EARTHDATA_USERNAMEandYOUR_EARTHDATA_PASSWORDwith your actual credentials. - Permissions (Linux/macOS): It's crucial to set the correct permissions for security. Open a terminal and type:
chmod 600 ~/.netrc
- Location:
3. Interface Overview
The application features a single main window divided into sections:
- Get Elevation for Point:
Latitude: Field to enter latitude (decimal degrees, e.g., 45.0).Longitude: Field to enter longitude (decimal degrees, e.g., 7.0).Get Elevation(Button): Starts the elevation lookup for the specified point. Downloads necessary data (HGT and browse image) if not found in the cache.Result: Label displaying the found elevation (in meters), a "nodata" message, or an error.Show Browse Image (2D)(Button): (Enabled after success) Opens a separate window (using Matplotlib) showing the preview image of the tile containing the point, with the name and source overlaid. Allows zooming and panning.Show DEM Tile (3D)(Button): (Enabled after success) Opens a separate window (using Matplotlib) showing an interactive 3D plot of the elevation data from the tile containing the point. Allows rotation, zooming, and panning.
- Pre-Download Tiles for Area:
Min Lat,Max Lat,Min Lon,Max Lon: Fields to define the boundaries of a rectangular area to download.Download Area Tiles(Button): Starts the background download of all HGT data (extracted) and browse images for all tiles intersecting the specified area.Show Area Browse Images (2D)(Button): (Enabled after successful area download) Opens a separate window (using Matplotlib) showing a mosaic of the preview images for the tiles in the downloaded area, with a red grid and tile names overlaid. Allows zooming and panning.Status: Label showing the status of the area download (Idle, Downloading, Complete, Error).
4. Detailed Functionality
- Get Elevation:
- Enter valid Latitude and Longitude.
- Click "Get Elevation".
- The application determines the required 1x1 degree DEM tile.
- Checks if the extracted HGT file exists in the local cache (
elevation_cache/hgt_tiles/). - If not exists:
- Connects to the NASA server using
.netrccredentials. - Downloads the
.zipfile containing HGT data. - Extracts the
.hgtfile into the local cache (hgt_tiles). - Attempts to download the public
.jpgbrowse image into the local cache (browse_images).
- Connects to the NASA server using
- If exists (or after download):
- Opens the local
.hgtfile. - Reads the elevation value for the exact coordinates.
- Displays the result in the "Result" label.
- Enables the "Show Browse Image (2D)" and "Show DEM Tile (3D)" buttons.
- Opens the local
- Download Area:
- Enter the geographic boundaries of the area.
- Click "Download Area Tiles".
- The application calculates which 1x1 degree tiles are needed.
- For each required tile:
- Checks if the extracted HGT file already exists in the cache.
- If not, performs steps 5a-5c of "Get Elevation".
- Independently of whether the HGT existed, checks if the browse image exists in the cache and attempts to download it if missing.
- The operation runs in the background to keep the interface responsive. Status is shown in the "Status" label.
- Upon completion, a message summarizes how many tiles were processed and how many HGT files were actually downloaded/extracted. The "Show Area Browse Images (2D)" button is enabled.
- 2D Visualization (Browse Image - Single Tile):
- Successfully get the elevation for a point.
- Click "Show Browse Image (2D)".
- The application looks for the corresponding browse image in the cache (
browse_images). - If found, it loads the image and adds the tile name and source as an overlay.
- Displays the image in a new interactive Matplotlib window.
- 3D Visualization (DEM Tile):
- Successfully get the elevation for a point.
- Click "Show DEM Tile (3D)".
- The application looks for the corresponding HGT file in the cache (
hgt_tiles). - If found, it reads the elevation data as a NumPy array.
- Generates a 3D surface plot using Matplotlib (with subsampling for performance).
- Displays the plot in a new interactive Matplotlib window.
- 2D Visualization (Area - Browse Mosaic):
- Successfully download an area using "Download Area Tiles".
- Click "Show Area Browse Images (2D)".
- The application looks for all browse images corresponding to the tiles in the requested area within the cache (
browse_images). - Loads the found images.
- Creates a composite image by "stitching" together the available images (uses gray placeholders if an image is missing).
- Draws a red grid to separate tiles and adds the name label to each tile.
- Displays the composite image in a new interactive Matplotlib window.
5. Common Use Cases
- Finding the Altitude of a Specific Location:
- Launch the application.
- Enter the location's latitude and longitude into the respective fields.
- Click "Get Elevation".
- Read the result in the "Result" label. The first access might take a few seconds for the download.
- (Optional) Click "Show Browse Image (2D)" to see the general appearance of the area from satellite/radar.
- (Optional) Click "Show DEM Tile (3D)" to explore the terrain relief in 3D.
- Checking Elevation Offline (Data Already Downloaded):
- Launch the application.
- Enter the latitude and longitude of a point within an area whose data has already been downloaded (in the
elevation_cache). - Click "Get Elevation".
- The result will appear almost instantly as data is read locally.
- Preparing Data for an Area Before Going Offline:
- Launch the application (with an active internet connection).
- Identify the boundaries (min/max lat/lon) of the area of interest.
- Enter these boundaries in the "Pre-Download Tiles for Area" section.
- Click "Download Area Tiles".
- Wait for completion (monitor the "Status" label and console logs). This may take time depending on the area size and connection speed.
- (Optional) Click "Show Area Browse Images (2D)" to visually confirm which tiles were downloaded.
- You can now use the application offline to get quick elevations for any point within the downloaded area.
- Visually Exploring a Single Tile:
- Enter the coordinates of any point within the tile you are interested in.
- Click "Get Elevation" (even if you know the elevation, this ensures the tile is available and enables the buttons).
- Click "Show Browse Image (2D)" or "Show DEM Tile (3D)".
- Getting an Overview of a Region:
- Ensure you have already downloaded the desired area using "Download Area Tiles".
- Click "Show Area Browse Images (2D)".
- Explore the composite image using Matplotlib's zoom/pan tools to see the tile layout and the general appearance of the region.
6. Notes and Troubleshooting
- Download Errors:
- 401/403 (Unauthorized/Forbidden): Problem with Earthdata Login credentials in your
.netrcfile. Check username, password, and the machine nameurs.earthdata.nasa.gov. - 404 (Not Found): The requested file (HGT zip or browse jpg) does not exist at the specified URL. This could indicate a gap in NASA's data for that area or an issue with the URL construction (check URL constants in
elevation_manager.py). - Network Errors/Timeouts: Temporary connection issues. The script attempts a short retry, but persistent errors require a stable connection.
- 401/403 (Unauthorized/Forbidden): Problem with Earthdata Login credentials in your
.netrcFile: Ensure it's in the correct directory and has restricted permissions (Linux/macOS).- Missing Dependencies: If libraries (Rasterio, Pillow, Matplotlib) are missing, the application will show warning messages on startup and/or errors when trying to use associated features. Install missing libraries with
pip. - 3D Performance: Rendering a full 3D tile can be intensive. Subsampling helps, but it might still be slow for very complex areas or less powerful machines.
- Blocking Windows: The Matplotlib visualization windows (2D and 3D) are run in separate processes to avoid blocking the main GUI, but the Matplotlib window itself will wait for user interaction or closure.
- Logs: Always check the output in the console/terminal where you launched the application for detailed log messages, especially if errors occur.