turf-rs

Crates.ioturf-rs
lib.rsturf-rs
version0.1.1
created_at2025-08-25 16:06:53.569439+00
updated_at2025-08-25 22:55:31.640909+00
descriptionA Rust library for advanced geospatial analysis based on Turf, providing powerful tools for manipulating and optimizing geometric data
homepage
repositoryhttps://gitlab.com/public-sources1/rust/turf-rs
max_upload_size
id1809749
size91,263
SonickSeven (sonickseven)

documentation

https://docs.rs/crate/turf-rs/latest

README

TURF-RS

A Rust library for advanced geospatial analysis, providing powerful tools for manipulating and optimizing geometric data.

Features

  • Dissolve: Union multiple polygons into a single, unified geometry. This is useful for merging adjacent or overlapping areas into a single feature.
  • Clear Polygons: Clean and simplify polygon geometries by removing redundant vertices, such as duplicate and collinear points. This helps to optimize storage and improve rendering performance.

Requirements

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

Usage

Dissolve

The dissolve function takes a vector of polygons and returns a single, merged polygon.

Example dissolve

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);
        }
    }
}

Clear Polygons

The clear_polygons function simplifies polygon geometries by removing duplicate and collinear points.

Example clear geometries inside of polygon

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);
}

How to use?

Add the following to your Cargo.toml file:

[dependencies]
turf-rs = "0.1.0"

Contributing

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!

License

This project is licensed under the terms of the MIT license or the Apache License 2.0.

Commit count: 0

cargo fmt