{"id":17204402,"url":"https://github.com/urschrei/polylabel-rs","last_synced_at":"2025-04-04T14:05:33.587Z","repository":{"id":39636968,"uuid":"65944929","full_name":"urschrei/polylabel-rs","owner":"urschrei","description":"A Rust implementation of the Polylabel algorithm, with FFI.","archived":false,"fork":false,"pushed_at":"2025-03-25T12:17:34.000Z","size":1084,"stargazers_count":54,"open_issues_count":4,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T13:06:57.682Z","etag":null,"topics":["algorithm","computational-geometry","ffi","geo","geospatial","gis","mapping","rust","rust-library"],"latest_commit_sha":null,"homepage":"https://docs.rs/polylabel","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/urschrei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-17T21:57:32.000Z","updated_at":"2025-02-20T17:33:04.000Z","dependencies_parsed_at":"2022-09-20T06:22:01.722Z","dependency_job_id":"724cb495-5865-48a3-b99f-0c1a194cc1da","html_url":"https://github.com/urschrei/polylabel-rs","commit_stats":{"total_commits":302,"total_committers":8,"mean_commits":37.75,"dds":0.08609271523178808,"last_synced_commit":"19103808fe45fa7917d5202512b54f72ba359947"},"previous_names":[],"tags_count":66,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urschrei%2Fpolylabel-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urschrei%2Fpolylabel-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urschrei%2Fpolylabel-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urschrei%2Fpolylabel-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/urschrei","download_url":"https://codeload.github.com/urschrei/polylabel-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190226,"owners_count":20898699,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","computational-geometry","ffi","geo","geospatial","gis","mapping","rust","rust-library"],"created_at":"2024-10-15T02:21:39.249Z","updated_at":"2025-04-04T14:05:33.563Z","avatar_url":"https://github.com/urschrei.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"[![Test and Build](https://github.com/urschrei/polylabel-rs/actions/workflows/rust.yml/badge.svg)](https://github.com/urschrei/polylabel-rs/actions/workflows/rust.yml) [![Coverage Status](https://coveralls.io/repos/github/urschrei/polylabel-rs/badge.svg?branch=master)](https://coveralls.io/github/urschrei/polylabel-rs?branch=master)\n[![](https://img.shields.io/crates/v/polylabel.svg)](https://crates.io/crates/polylabel)\n# Polylabel-rs\nA Rust implementation of the [Polylabel](https://github.com/mapbox/polylabel) algorithm\n\nThe orange dot is the polygon centroid. The teal dot is the ideal label position. Red boxes show the search space.\n[![GIF](output.gif)]()\n\nYou can generate this visualisation yourself by cloning this repo, switching to the [`visualise`](https://github.com/urschrei/polylabel-rs/tree/visualise) branch, and opening the [`visualise.ipynb`](https://github.com/urschrei/polylabel-rs/blob/visualise/visualise.ipynb) Jupyter notebook, then stepping through the cells. You can also easily visualise a Polygon of your own using the notebook.\n\n## How to Use\n```rust\nextern crate polylabel;\nuse polylabel::polylabel;\n\nextern crate geo;\nuse geo::{Point, Polygon};\n\nlet coords = vec![\n    (0.0, 0.0),\n    (4.0, 0.0),\n    (4.0, 1.0),\n    (1.0, 1.0),\n    (1.0, 4.0),\n    (0.0, 4.0),\n    (0.0, 0.0)\n];\nlet poly = Polygon::new(coords.into(), vec![]);\nlet label_pos = polylabel(\u0026poly, \u00260.10);\n// Point(0.5625, 0.5625)\n```\n## Command-Line Tool\nA command-line tool is available: `cargo install polylabel_cmd`. This enables the `polylabel` command, which takes a GeoJSON file as input, as well as an optional (`-t / --tolerance`) tolerance value. See more at [crates.io](https://crates.io/crates/polylabel_cmd).\n\n## Documentation\nhttps://docs.rs/polylabel\n\n## FFI\n### Enable the Cargo `ffi` and `headers` features to enable this functionality\nCall `polylabel_ffi` with the following three mandatory arguments:\n- [`Array`](https://docs.rs/polylabel/1.0.3/polylabel/struct.Array.html) (a struct with two fields):\n    - `data`: a void pointer to an array of two-element `c_double` arrays, each of which represents a point on the exterior Polygon shell)\n    - `len`: the length of the `data` array, a `size_t`\n- [`WrapperArray`](https://docs.rs/polylabel/1.0.3/polylabel/struct.WrapperArray.html) (a struct with two fields):\n    - `data`: a void pointer to an array of `Array`s, each entry representing an interior Polygon ring. Empty if there are no rings.\n    - `len`: the length of the `data` array, a `size_t`. 0 if it's empty.\n- `tolerance`, a `c_double`\n\nThe function returns a [struct](https://docs.rs/polylabel/1.0.3/polylabel/struct.Position.html) with two `c_double` fields:\n- `x_pos`\n- `y_pos`\n\nHeaders are provided in the `include` directory. A Python example is available in [`ffi.py`](ffi.py)\n\nAn auto-generated header file is available at [`include/header.h`](include/header.h)\n\n## Performance vs Accuracy\nUsing 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](https://gis.stackexchange.com/questions/8650/measuring-accuracy-of-latitude-and-longitude/8674#8674) for some guidance on the accuracy provided by each decimal place.\n### CPU Optimizations\nBuild using the `target-cpu=native` `RUSTFLAG` for a ~10 % perf improvement\n\n## Binaries\nare available in [releases](https://github.com/urschrei/polylabel-rs/releases).\n\n## License\n[MIT](license.txt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furschrei%2Fpolylabel-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Furschrei%2Fpolylabel-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furschrei%2Fpolylabel-rs/lists"}