layout: default title: gtopo2ascii parent: Grid Tools nav_order: 35 —
gtopo2ascii
Description
gtopo2ascii is a command-line utility for converting binary Digital Elevation Model (DEM) data, specifically in the GTOPO30 format, into a simple three-column ASCII XYZ format (latitude longitude elevation).
The tool reads a binary .DEM file containing 16-bit integer elevation data and its corresponding ASCII .HDR header file. It uses the metadata from the header to correctly interpret the binary data, calculate the geographic coordinate for each pixel, and stream the results to standard output.
Usage
gtopo2ascii -in <file_prefix> [OPTIONS] > output.xyz
Arguments
| Option | Description | Default / Example |
|---|---|---|
-in <file_prefix> | Required. Specifies the prefix for the input files. The tool expects to find two files: <file_prefix>.DEM (the binary data) and <file_prefix>.HDR (the ASCII header). | -in W140N90 |
-invalid <value> | Specifies the integer value within the .DEM file that represents “no data”. These pixels will be skipped. | -99999 |
-maxlat <degrees> | Defines the maximum latitude (northern boundary) of a geographic bounding box for extraction. | -maxlat 48.0 |
-minlat <degrees> | Defines the minimum latitude (southern boundary) of a geographic bounding box for extraction. | -minlat 45.0 |
-maxlon <degrees> | Defines the maximum longitude (eastern boundary) of a geographic bounding box for extraction. | -maxlon -63.0 |
-minlon <degrees> | Defines the minimum longitude (western boundary) of a geographic bounding box for extraction. | -minlon -67.0 |
-v | Enable verbose output. |
How It Works
- File Opening: Opens the binary
.DEMfile for reading and the ASCII.HDRfile for reading. - Header Parsing: Reads the
.HDRfile to extract metadata such asncols(number of columns),nrows(number of rows),latitude,longitude(of the origin), andcellsize(pixel resolution in degrees). - Data Processing Loop: Reads the
.DEMfile, which contains 16-bit signed integer elevation values, row by row and column by column:- Reads a 16-bit
elevationvalue. - If
elevationmatches theinvalid_value, it is skipped. - Calculates the
latitudeandlongitudefor the current pixel using the origin coordinates andcellsize. - If geographic bounding box options (
-maxlat,-minlat,-maxlon,-minlon) are specified, it checks if the current pixel falls within these bounds. - Prints
latitude,longitude, andelevationto standard output.
- Reads a 16-bit
Output Files
The tool prints space-separated latitude longitude elevation values to standard output, which can be redirected to a file.
Dependencies
support.h: For general utility functions and error handling.
Notes
GTOPO30 is a global digital elevation model with a horizontal grid spacing of 30 arc seconds. This tool provides a way to extract subsets of this data in a simple, generic ASCII XYZ format suitable for further processing or visualization in other GIS or plotting software. It handles the binary 16-bit signed integer format specific to GTOPO30.
Output
The tool prints space-separated latitude longitude elevation values to standard output, which can be redirected to a file.