Giter Site home page Giter Site logo

geos's Introduction

geos

Rust bindings for GEOS C API.

The supported geos version is >= 3.5

Disclaimer

GEOS can be a tad strict on the validity on the input geometry and is prone to crash on invalid input, so they need to be checked in the wrapper. This project is checked with valgrind, but if you stumble on a crash feel free to open an issue explaining the problem.

Usage example

You can check the examples in the examples/ directory.

Constructing geometries from WKT:

use geos::Geom;

let gg1 = geos::Geometry::new_from_wkt("POLYGON ((0 0, 0 5, 6 6, 6 0, 0 0))")
                         .expect("invalid WKT");
let gg2 = geos::Geometry::new_from_wkt("POLYGON ((1 1, 1 3, 5 5, 5 1, 1 1))")
                         .expect("invalid WKT");
let gg3 = gg1.difference(&gg2).expect("difference failed");
assert_eq!(
    gg3.to_wkt_precision(0).expect("to_wkt failed"),
    "POLYGON ((0 0, 0 5, 6 6, 6 0, 0 0), (1 1, 5 1, 5 5, 1 3, 1 1))",
);

"Preparing" the geometries for faster predicates (intersects, contains, etc.) computation on repetitive calls:

let g1 = geos::Geometry::new_from_wkt("POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))")
                        .expect("invalid WKT");
let g2 = geos::Geometry::new_from_wkt("POLYGON ((1 1, 1 3, 5 5, 5 0, 1 1))")
                        .expect("invalid WKT");

let pg1 = geos::PreparedGeometry::new(&g1)
                                 .expect("PreparedGeometry::new failed");
let result = pg1.intersects(&g2).expect("intersects failed");
assert_eq!(result, true);

Conversion from geo

geo's objects can be converted into GEOS to use all geos algorithms.

Complete example can be found in examples/from_geo.rs

use geos::from_geo::TryInto;
use geos::geo_types::{LineString, Coordinate, Polygon};

// first we create a Geo object
let exterior = LineString(vec![
    Coordinate::from((0., 0.)),
    Coordinate::from((0., 1.)),
    Coordinate::from((1., 1.)),
]);
let interiors = vec![
    LineString(vec![
        Coordinate::from((0.1, 0.1)),
        Coordinate::from((0.1, 0.9)),
        Coordinate::from((0.9, 0.9)),
    ]),
];
let p = Polygon::new(exterior, interiors);
// and we can create a Geos geometry from this object
let geom: geos::Geometry = (&p).try_into()
                               .expect("failed conversion");
// do some stuff with geom

Voronoi

Voronoi diagrams computation are available in the bindings.

For those to be easier to use with geo some helpers are available in voronoi.rs.

use geos::compute_voronoi;
use geos::geo_types::Point;

let points = vec![
    Point::new(0., 0.),
    Point::new(0., 1.),
    Point::new(1., 1.),
    Point::new(1., 0.),
];

let voronoi = compute_voronoi(&points, None, 0., false)
                  .expect("compute_voronoi failed");

Static build

By default, this crate links dynamically. If you want to link statically, use the static feature.

Contributing

Only a subset of geos has been implemented, feel free to add wrappers for missing features.

All added features needs to be tested and this being a C wrapper, valgrind runs on all examples/tests to check that no bugs / memory leaks are lurking.

geos's People

Contributors

guillaumegomez avatar antoine-de avatar mthh avatar texitoi avatar amatissart avatar frewsxcv avatar gauteh avatar crutt avatar enerqi avatar aboseley avatar gschulze avatar rofrol avatar rudlorenz avatar thomasantony avatar msakuta avatar nlehuby avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.