Skip to main content

A Rust implementation of the Polylabel algorithm for finding optimum polygon label positions, with Python binding.

Project description

Pylylabel

A Rust implementation of the Polylabel algorithm.

This is a fork of polylabel-rs. Pylylabel's polylabel function also returns the distance from the label position to the polygon. Python binding is provided using PyO3.

The orange dot is the polygon centroid. The teal dot is the ideal label position. Red boxes show the search space. GIF

How to Use

extern crate pylylabel;
use pylylabel::polylabel;

extern crate geo;
use geo::{Point, Polygon};

let coords = vec![
    (0.0, 0.0),
    (4.0, 0.0),
    (4.0, 1.0),
    (1.0, 1.0),
    (1.0, 4.0),
    (0.0, 4.0),
    (0.0, 0.0)
];
let poly = Polygon::new(coords.into(), vec![]);
let label_pos, distance = polylabel(&poly, &0.10);
// Point(0.5625, 0.5625), 0.5625
from pylylabel import polylabel
from shapely.geometry import Polygon

exterior = [
    [0.0, 0.0],
    [4.0, 0.0],
    [4.0, 1.0],
    [1.0, 1.0],
    [1.0, 4.0],
    [0.0, 4.0],
    [0.0, 0.0]
]
pol = Polygon(exterior)
x, y, distance = polylabel(pol, tolerance=0.1)
# 0.5625, 0.5625, 0.5625

Documentation

https://docs.rs/polylabel

Performance vs Accuracy

Using a 4-core 2.3 GHz Intel Core i5, finding a label position on a ~9k-vertex polygon (representing the Norwegian mainland) using a tolerance of 1.0 takes around 9 ms. Depending upon the dimensions of your polygon(s), you may require a higher tolerance (i.e. a smaller number). See here for some guidance on the accuracy provided by each decimal place.

Build

Requirements:

maturin build --release

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylylabel-4.0.0.tar.gz (317.9 kB view hashes)

Uploaded Source

Built Distributions

pylylabel-4.0.0-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl (953.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ x86-64

pylylabel-4.0.0-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.whl (984.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

pylylabel-4.0.0-cp310-none-win_amd64.whl (118.7 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pylylabel-4.0.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl (953.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ x86-64

pylylabel-4.0.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl (984.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ i686

pylylabel-4.0.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (430.7 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pylylabel-4.0.0-cp310-cp310-macosx_10_7_x86_64.whl (221.3 kB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

pylylabel-4.0.0-cp39-none-win_amd64.whl (118.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pylylabel-4.0.0-cp39-none-win32.whl (114.7 kB view hashes)

Uploaded CPython 3.9 Windows x86

pylylabel-4.0.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl (953.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ x86-64

pylylabel-4.0.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (984.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ i686

pylylabel-4.0.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (430.8 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pylylabel-4.0.0-cp39-cp39-macosx_10_7_x86_64.whl (221.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

pylylabel-4.0.0-cp38-none-win_amd64.whl (118.7 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pylylabel-4.0.0-cp38-none-win32.whl (114.8 kB view hashes)

Uploaded CPython 3.8 Windows x86

pylylabel-4.0.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl (953.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ x86-64

pylylabel-4.0.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl (984.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ i686

pylylabel-4.0.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (431.1 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pylylabel-4.0.0-cp38-cp38-macosx_10_7_x86_64.whl (221.6 kB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

pylylabel-4.0.0-cp37-none-win_amd64.whl (118.7 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

pylylabel-4.0.0-cp37-none-win32.whl (115.0 kB view hashes)

Uploaded CPython 3.7 Windows x86

pylylabel-4.0.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (952.9 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.5+ x86-64

pylylabel-4.0.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.whl (984.2 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.5+ i686

pylylabel-4.0.0-cp36-none-win_amd64.whl (119.0 kB view hashes)

Uploaded CPython 3.6 Windows x86-64

pylylabel-4.0.0-cp36-none-win32.whl (114.9 kB view hashes)

Uploaded CPython 3.6 Windows x86

pylylabel-4.0.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (953.1 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.5+ x86-64

pylylabel-4.0.0-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.whl (984.3 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.5+ i686

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page