Documentation Index
Fetch the complete documentation index at: https://mintlify.com/thareUSGS/GDAL_scripts/llms.txt
Use this file to discover all available pages before exploring further.
Overview
gdal2PLY.py converts Digital Elevation Models (DEMs) or Digital Terrain Models (DTMs) into 3D binary PLY (Polygon File Format) meshes suitable for 3D visualization and analysis.
Purpose
Create a 3D binary PLY format file from a GDAL-supported DEM/DTM raster, generating a triangulated mesh representation of terrain data. Original Author: Jake (posted on GIS StackExchange)Modifications: Trent Hare, USGS
Source: GIS StackExchange
Installation Requirements
conda install gdal
Command Syntax
Parameters
Input DEM/DTM file (any GDAL-supported raster format)
Output PLY mesh file (binary format)
Usage Examples
Basic DEM to PLY Conversion
Complete Workflow with NoData Handling
NoData Handling
NoData Work-around Process
1. Identify Minimum ElevationComputed Min/Max=-2790.594,5432.123
2. Set NoData to Safe Value
Set GDAL NoData to the next round value below the minimum:
How It Works
Vertex Array Creation
The script creates a vertex array from the raster (seegdal2PLY.py:69-78):
Triangle Index Generation
Creates triangulated faces from the grid (seegdal2PLY.py:81-93):
PLY File Structure
The output PLY file contains:- Header: Binary little/big-endian format specification
- Vertex Properties: x, y, z coordinates (float32)
- Face Definitions: Triangle vertex indices (int32)
- Binary Data: Efficient storage of geometry
PLY Format Specification
Example PLY header generated:Performance Considerations
Large DEMs: For very large DEMs, consider resampling before conversion to reduce mesh complexity and file size.
Optimization Tips
1. Resample Large Datasets- Vertices: ~1.2 GB
- Triangles: ~2.4 GB
- Total memory usage: ~3-4 GB
Viewing PLY Files
Recommended Software
- MeshLab: Open-source mesh processing tool
- CloudCompare: Point cloud and mesh viewer
- Blender: 3D modeling and visualization
- ParaView: Scientific visualization
Load in MeshLab
Related Tools
PlateVertex2Obj
For converting PDS Shapemodel or Plate-Vertex formats to Wavefront OBJ format, use the companion toolPlateVertex2Obj.py.
Usage
Purpose
Convert simple 3D PDS Shapemodel or Plate-Vertex files to Alias WaveFront OBJ format. This assumes original vertices are listed in sequential order (1, 2, 3, 4, …n).Example: NEAR Eros Shape Model
Download from SBN Tools:File Format
Input file structure:Technical Details
Coordinate System
The PLY mesh uses the same coordinate system as the input raster:- X, Y: Derived from geotransform (map coordinates)
- Z: Elevation values from raster band
Mesh Topology
Each grid cell creates two triangles:(a, a+width, a+width+1) and (a, a+width+1, a+1)
Source Code Reference
gdal2PLY.py:28-62- PLY file writing with binary format supportgdal2PLY.py:69-78- Vertex array creation from rastergdal2PLY.py:81-93- Triangle index generationPlateVertex2Obj.py:38-53- PDS to OBJ conversion loop