startinpy
A library for modelling and processing 2.5D terrains using a (2D) Delaunay triangulation.
The triangulation is computed in 2D, but the z-elevation of the vertices are kept.
The underlying code is written in Rust (so it's rather fast) and robust arithmetic is used (so it shouldn't crash).
startinpy uses the startin Rust library and adds several utilities and functions, for instance NumPy support for input/output, exporting to several formats, and easy-of-use.
startinpy allows you to:
- insert incrementally points
- delete vertices (useful for simplification, interpolation, and other operations)
- interpolate with several methods: TIN, natural neighbours, IDW, Laplace, etc.
- use other useful terrain Python libraries that are also NumPy-based, eg laspy, rasterio, meshio
- output the TIN to several formats: OBJ, PLY, GeoJSON, and CityJSON
- store extra attributes with the vertices (the ones from LAS/LAZ)
Documentation
https://startinpy.rtfd.io
Installation
pip
To install the latest release: pip install startinpy
(watch out: this does not work with Linux currently, it installs an old version!)
If you want to compile it yourself
- install latest Rust
- install maturin
maturin build --release
cd ./target/wheels/
pip install [name-wheel].whl
will install it to your local Python
Development
- install Rust (v1.39+)
- install maturin
maturin develop
- move to another folder, and
import startinpy
shouldn't return any error
Testing
To run the automated test suite:
- install the test requirements:
pip install -r tests/requirements.txt
pytest
Examples
The folder ./demo
contains a few examples.
import laspy
import numpy as np
import startinpy
las = laspy.read("../data/small.laz")
pts = np.vstack((las.x, las.y, las.z)).transpose()
dt = startinpy.DT()
dt.insert(pts)
try:
dt.remove(4)
except Exception as e:
print(e)
print("# vertices:", dt.number_of_vertices())
print("# triangles:", dt.number_of_triangles())
print("CH: ", dt.convex_hull())
vi = 235
one_random_pt = dt.points[vi]
print("one random point:", one_random_pt)
print(dt.incident_triangles_to_vertex(vi))
zhat = dt.interpolate({"method": "TIN"}, [[85718.5, 447211.6]])
print("result: ", zhat[0])