/phstl

Convert GDAL rasters (like GeoTIFF heightmaps) to 3D STL surfaces.

Primary LanguagePythonMIT LicenseMIT

phstl

Convert GDAL rasters to STL mesh. Intended to produce landscape models from GeoTIFF heightmaps.

Example

Here's a sample GeoTIFF heightmap:

tif input

To create a surface mesh from it, type:

phstl example.tif example.stl

mesh output

By default, the output is scaled such that one mesh unit represents one unit of the input coordinate system. Since the input image resolution is 46 x 38 at about 12.8 feet per pixel (thus an extent of roughly 592 x 482 feet), the output mesh extent is about 580 x 470 units.

To scale the output to fit a certain size, use the -x or -y extent option. To exaggerate vertical relief, use the -z factor option. To anchor the dataset's lowest elevation at Z = 0, use the -c option to automatically clip elevation values. Here's a second example:

phstl -x 100 -z 3 -c example.tif example2.stl

customized mesh output

The output surface mesh is not a manifold object. Use another tool to solidify the model in preparation for 3D printing. For examples, see these brief tutorials for Blender or Meshmixer.

Usage

usage: phstl.py [-h] [-x X] [-y Y] [-z Z] [-b BASE] [-c] [-v] RASTER [STL]

Convert a GDAL raster (like a GeoTIFF heightmap) to an STL terrain surface.

positional arguments:
  RASTER                Input heightmap image
  STL                   Output STL path (stdout)

optional arguments:
  -h, --help            show this help message and exit
  -x X                  Fit output x to extent (mm)
  -y Y                  Fit output y to extent (mm)
  -z Z                  Vertical scale factor (1)
  -b BASE, --base BASE  Base height (0)
  -c, --clip            Clip z to minimum elevation
  -v, --verbose         Print log messages
  --band BAND           Raster data band (1)
  -m MINIMUM, --minimum MINIMUM
                        Omit vertices below minimum elevation
  -M MAXIMUM, --maximum MAXIMUM
                        Omit vertices above maximum elevation

Prerequisites

License

This project is released under an open source MIT license.