This Python script generates 3D printable STL files of geographical districts from a Digital Elevation Model (DEM) and a GeoJSON file. It's designed to create physical terrain models for visualization, education, or personal projects.
The script relies on several Python libraries. Install them via pip:
pip install geopandas rasterio numpy pyvista shapelyRun the script from the command line, providing the paths to your district boundaries and DEM files.
Basic Command
python your_script_name.py path/to/districts.geojson path/to/dem.tifOptional Arguments
Customize the output with the following flags:
-o, --output <folder_name>: Specifies the output directory for the STL files. Defaults tostl_districts.-e, --exaggeration <factor>: Sets the vertical exaggeration for terrain features. A higher value makes mountains appear taller. The default is5.-s, --scale <mm>: Defines the target size of the model's longest side in millimeters. Defaults to180.-c, --epsg <code_number>: Reprojects input files to a specified EPSG coordinate system. This is crucial if your GeoJSON and DEM files use different systems. For example, use4326for WGS 84.
Example
This command generates a model with a vertical exaggeration of 10 and a longest side of 200 mm, reprojecting the data to EPSG 32633.
python your_script_name.py data/districts.geojson data/elevation.tif -o output_models -e 10 -s 200 -c 32633
I used https://www.mapsforeurope.org/datasets/euro-dem for a DEM of europe then found out that ESPG:4026 fits my country exactly (Moldova)
my command looks like this.
python3 script.py moldova_districts.geojson eurodem.tif -c 4026
warning: it did turn a 1gb DEM (eurodem) to a temporary 41gb DEM. But hey it deletes itself after usage and works.Districts File (.geojson)
A GeoJSON file containing the district polygons. The script processes each polygon to create a separate STL file. By default, it uses the "shapeName" property for naming the output files; otherwise, it assigns a generic name like district_0.
DEM File (.tif)
A GeoTIFF file containing elevation data. The resolution of this file dictates the detail of the final 3D model.