Topogmesh: 3D printing the planet
Overview
Topogmesh generates .3mf files suitable for 3D printing from terrain .tif files. It can also use .geojson files to define custom areas of terrain to include in the model. It also supports generating detailed meshes for cities based off LIDAR data and uses OSM data to add seperate layers to the model.
Installation
Topogmesh is available on PyPI and can be installed with pip:
pip install topogmesh
How to use
Creating a mesh for single Raster
To create a rectangular 3D-printable model from a TIF file, use topogmesh.mesh_from_tif.
You need to provide:
tif_path: The path to the raster you want to print.max_length: The maximum horizontal size of the model in millimetres (the longest side of the rectangle).max_height: The total height of the 3D model in millimetres. The tallest point of the raster will be scaled to this height, and all other points are scaled proportionally.
Optional Parameters:
base_height: This controls the gap between base of the model and the lowest point of the raster. If not specified, base_height defaults to 1 mm.
import topogmesh
london_mesh = topogmesh.mesh_from_tif(
tif_path='london.tif',
max_length=100,
max_height=30,
base_height=5,
)
topogmesh.export_mesh_to_3mf(london_mesh, 'london.3mf')
This can also be done using the command line with the following equivalent command.
topogmesh mesh_from_tif \
--tif london.tif \
--output london.3mf \
--max-length 100 \
--max-height 30 \
--base-height 5
Custom Shaped Models
This function allows you to create models with custom shapes and select a specific region from a group of rasters. It also supports the use of OSM tags to seperate the model into different layers.
You need to provide:
shp_path: The path to the geojson filetif_paths: The paths to the relevant raster data (make sure you have the right data to cover the entire shape file)max_length: The maximum horizontal size of the model in millimetres (the longest side of the rectangle).max_height: The total height of the 3D model in millimetres. The tallest point of the raster will be scaled to this height, and all other points are scaled proportionally.
Optional Parameters:
base_height: This controls the gap between base of the model and the lowest point of the raster. If not specified, base_height defaults to 1 mm.osm_tags: A list of OpenStreetMap tag dictionaries (in JSON format) used to overlay features such as rivers, roads, or buildings on the mesh. NOTE, if a feature contains two or more of the tags provided it will default to being part of the first layer which it contains the tag for.
import topogmesh
everest_mesh = topogmesh.mesh_from_shape_file(
shp_path='everest.geojson',
tif_paths=['N27E086.tif', 'N28E086.tif', 'N29E086.tif'],
max_length=200,
max_height=60,
base_height=5,
osm_tags=[{'natural': 'water'}]
)
topogmesh.export_mesh_to_3mf(everest_mesh, 'everest.3mf')
Alternatively, you can use the command line.
topogmesh mesh_from_shape_file \
--shape everest.geojson \
--tifs N27E086.tif N28E086.tif N29E086.tif \
--output everest.3mf \
--base-height 3 \
--max-length 200 \
--max-height 60 \
--osm-tags '{"natural": "water"}'
Creating a mesh from a shapefile and LIDAR data
To generate a 3D-printable model from a polygon shapefile (e.g. a boundary) and corresponding DSM/DTM TIF tiles, use topogmesh.mesh_from_uk_shape_file. This function creates a model for the underlying terrain using the DTM data provided, and then uses the DSM files to add different layers based on OSM data. For example using the tag '{'building' : 'yes'}' will add a component to the model which contains models for all the buildings within the chosen area. This is useful if you want to pick out individual features to include or if you want to change the colour of a specific feature to make it stand out. To find out which tags you need for the features you want, visit the OSM website.
You need to provide:
shape: Path to a polygon shapefile (either.geojsonor.shp) defining the region of interest.dsms: A list of Digital Surface Model (DSM).tiffiles covering the region.dtms: A list of Digital Terrain Model (DTM).tiffiles covering the region.output: Path where the generated.3mffile should be saved.max_length: The maximum horizontal size of the model in millimetres (the longest side of the bounding box).
Optional parameters:
base_height: Adds a gap between the print bed and the lowest point of the terrain (default: 1 mm).osm_tags: A list of OpenStreetMap tag dictionaries (in JSON format) used to overlay features such as rivers, roads, or buildings on the mesh. NOTE, if a feature contains two or more of the tags provided it will default to being part of the first layer which it contains the tag for.
import topogmesh
uk_mesh = topogmesh.mesh_from_uk_shape_file(
shape="buckingham_palace.geojson",
dsms=["dsm_tile1.tif", "dsm_tile2.tif"],
dtms=["dtm_tile1.tif", "dtm_tile2.tif"],
output="palace.3mf",
max_length=200,
base_height=2,
osm_tags=[{"building": ["yes", "palace"]}, {"natural": "water"}],
)
The equivalent command is:
topogmesh mesh_from_uk_shape_file \
--shape buckingham_palace.geojson \
--dsms dsm_TQ2575 dsm_TQ2580 \
--dtms dtm_TQ2575 dtm_TQ2580 \
--output palace.3mf \
--max-length 200 \
--base-height 2 \
--osm-tags '{"building": ["yes", "palace"]}' '{"natural": "water"}'
Downloading UK LIDAR data
To get the right DTM's and DSM's for a particular region of the uk, you can either download them manually from the UK Government Website, or use the topogmesh command which automatically downloads the tiles needed for a given geojson file.
You need to provide:
geojson: The path to the geojson file you want the tiles for.output_dir: The destination folder you want the LIDAR tiles to be saved to.
topogmesh download_tiles_for_uk_shape \
--geojson clare_college.geojson
--output-dir lidar_data
Thanks
Thank you to Dr Michael Winston Dales for supervising this project; providing very useful insights and creating Yirgacheffe which is integral to this library working. Also thank you to Professor Anil Madhavapeddy for overseeing this UROP and giving me this opportunity.
Metadata
Release files for topogmesh 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| topogmesh-0.1.7.tar.gz | 15.9 kB | Without provenance | Details for topogmesh-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| topogmesh-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for topogmesh-0.1.7-py3-none-any.whl |
Total release size: 32.1 kB
Release files / topogmesh-0.1.7.tar.gz
| Download URL | topogmesh-0.1.7.tar.gz |
|---|---|
| Size | 15.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
96b4e433e1c985d8138bc6fc3fc4230d3557da41966c4f8a1f22269f54ed56be
|
|
BLAKE2b-256 checksum How to use checksums |
79bcf1c42e27db5913e108b538b365af20bec521b91b42ae4205327193876ffe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.2
|
Release files / topogmesh-0.1.7-py3-none-any.whl
| Download URL | topogmesh-0.1.7-py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c4b8469ec530fbc5cdfe78507919200e5fb57a469072b5a88cb71bfefc8583ce
|
|
BLAKE2b-256 checksum How to use checksums |
5a3aaf4ae51c1a070e0114b77135813bd40db2a710a197377e17516bbb72533a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.2
|
Security for topogmesh 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.