Crates.io | turf-rs |
lib.rs | turf-rs |
version | 0.1.1 |
created_at | 2025-08-25 16:06:53.569439+00 |
updated_at | 2025-08-25 22:55:31.640909+00 |
description | A Rust library for advanced geospatial analysis based on Turf, providing powerful tools for manipulating and optimizing geometric data |
homepage | |
repository | https://gitlab.com/public-sources1/rust/turf-rs |
max_upload_size | |
id | 1809749 |
size | 91,263 |
A Rust library for advanced geospatial analysis, providing powerful tools for manipulating and optimizing geometric data.
On Debian-based systems, you need to install the libgeos-dev
package:
sudo apt-get update && sudo apt-get install -y libgeos-dev
**For others systems like mac or windows on official website of Geos
The dissolve
function takes a vector of polygons and returns a single, merged
polygon.
use geo::Polygon;
use turf::dissolve;
fn main() {
// Create some polygons to dissolve
let polygon1 = Polygon::new(
vec![
(0.0, 0.0),
(1.0, 1.0),
(1.0, 0.0),
(0.0, 0.0),
].into(),
vec![],
);
let polygon2 = Polygon::new(
vec![
(1.0, 0.0),
(2.0, 1.0),
(2.0, 0.0),
(1.0, 0.0),
].into(),
vec![],
);
let polygons = vec![polygon1, polygon2];
match dissolve_polygons(polygons) {
Ok(result) => {
println!("Polygons dissolved successfully!");
println!("Joined {} polygons into {}.", result.polygons_joined, result.all_polygons);
}
Err(e) => {
eprintln!("Error dissolving polygons: {}", e);
}
}
}
The clear_polygons
function simplifies polygon geometries by removing
duplicate and collinear points.
use geo::Polygon;
use turf::clean_coords;
fn main() {
// Create a polygon with redundant vertices
let polygon = Polygon::new(
vec![
(0.0, 0.0),
(0.5, 0.0), // Collinear point
(1.0, 0.0),
(1.0, 1.0),
(1.0, 1.0), // Duplicate point
(0.0, 1.0),
(0.0, 0.0),
].into(),
vec![],
);
let result = clean_coords(vec![polygon]);
println!("Polygon cleaned successfully!");
println!("Original vertices: {}", result.origal_vertices);
println!("Cleaned vertices: {}", result.cleaned_vertices);
}
Add the following to your Cargo.toml
file:
[dependencies]
turf-rs = "0.1.0"
We welcome contributions from the community! If you have an idea for a new feature, a bug fix, or an improvement to the documentation, please open an issue or submit a pull request on our GitHub repository.
Together, we can make turf-rs
the best geospatial library for Rust!
This project is licensed under the terms of the MIT license or the Apache License 2.0.