Polylabel-rs
A Rust implementation of the Polylabel algorithm
Visualised: The orange dot is the polygon centroid. The teal dot is the ideal label position.
You can generate this visualisation yourself by cloning this repo, switching to the visualise
branch, and opening the visualise.ipynb
Jupyter notebook, then stepping through the cells. You can also easily visualise a Polygon of your own using the notebook.
How to Use
extern crate polylabel;
use polylabel;
extern crate geo;
use ;
let coords = vec!;
let ls = LineString;
let poly = new;
let label_pos = polylabel;
// Point(0.5625, 0.5625)
Documentation
FFI
Call polylabel_ffi
with the following three mandatory arguments:
Array
(a void pointer to an array of two-elementc_double
s, the exterior Polygon ring)WrapperArray
(a void pointer to an array ofArray
s, the interior Polygon rings, empty if there are none)tolerance
, ac_float
The function returns a struct with two c_double
fields:
x_pos
y_pos
A Python example is available in ffi.py
Binaries
Binary libs for:
x86_64
*nix (built usingmanylinux1
, thus easy to include in Python 2.7 / 3.5 / 3.6 wheels) and OS Xi686
andx86_64
Windows
are available in releases.