We propose a library m4py, a toolbox to generate 3D maps and combine them with 3D printed objects (text, mesh, etc).
git clone https://github.com/jacquesfize/3DPrintedMapProject.git
cd 3DPrintedMapProject
pip install .
First, import the Map object:
from map import Map
To instatiate the Map object, we need the path to the raster file and the scale factor applied to the latter.
map3D = Map("data.tif",scale_factor=0.5)
Map
object are composed of:
- a raster
self.raster
- a mesh of the 3D transformed raster
self.map_mesh
- a list of geometries that will be extruded onto the raster
self.meshs
If you just want the 3D model of the raster and save it:
final_mesh = map3D.save_mesh("test.stl")
To add text in your 3D map, use the add_text
method like in the following:
map3D = map3D.add_text("placename", *(lat,lon), "fonts.ttf")
If you want to place any mesh at non-geographic coordinates, use the add_text
method like in the following:
map3D = map3D.add_text("placename", *(x,y), "fonts.ttf",raster_coords=True)
Similar to the add_text
method, you can add any mesh at any geographic coordinates with the add_mesh
method. For now, the mesh is defined by the numpy-stl
Mesh
object.
map3D = map3D.add_mesh(mesh.Mesh.from_file("test.stl"), 0, 0)
An example on how to produce 3D map with the current code
In addition to text and mesh, you can also extrude geometries in the 3D map. To do this, use the add_geometry
method like in the following:
geometry_dataframe = gpd.read_file('your_data.geojson')
map3D = map3D.add_geometry(geometry_dataframe, 10000)
To plot your 3D map, use the plot
method like in the following:
map3D.plot()
We use pyvista
to plot the 3D object therefore if you want to customize the plot rendering, you can use the plot
method like in pyvista
:
map3D.plot(cpos="xy")
This 3d map shows the refuges and hut in the Parc National des Écrins (France) area.
PS. Poor painting skills here🤦♂️
- Be able to clip mesh generated and to print the clipped meshes
- Rename map.py to avoid confusion with
map
in python - Write a better documentation
- drop numpy-stl for pyvista
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.