Google Encoded Polyline encoding & decoding in Rust.

Related tags

Geospatial polyline
Overview

polyline

Crates.io Build Status

Google Encoded Polyline encoding & decoding in Rust.

A Note on Coordinate Order

This crate uses Coordinate and LineString types from the geo-types crate, which encodes coordinates in (x, y) order. The Polyline algorithm and first-party documentation assumes the opposite coordinate order. It is thus advisable to pay careful attention to the order of the coordinates you use for encoding and decoding.

Documentation

Comments
  • Add FFI module

    Add FFI module

    I'm not sure whether there's interest in this, but this is an FFI module, allowing anything which can do C-type FFI to access the encoding and decoding functions, via a .so/.dylib/.dll. There are docs, tests, and I've written a Python package which uses the bindings.

    Other things: the docs are extensive, but the examples are in Rust, which is somewhat pointless. Compact examples using other languages (js?) would be great.

    opened by urschrei 6
  • crates publishing team

    crates publishing team

    πŸ‘‹ Hi @tmcw, you are the only "user-owner" of the polyline crate on crates.io, so only you can edit that crate's owners on crates.io.

    Following up on https://github.com/georust/meta/pull/21, I created a new polyline-publishers team for publishing to crates.io with you as maintainer.

    Could you please update the crate owners? Specifically:


    • [x] update polyline crate owners on crates.io:
    cd polyline
    
    # πŸ’₯ remove large publishing group
    cargo owner --remove github:georust:core
    
    # πŸ” add small publishing group
    cargo owner --add github:georust:polyline-publishers
    
    # you're currently the only user-owner of the crate. Consider adding another user-owner, 
    # that way if for some reason you become inaccessible we have someone else who can edit the owners. 
    # See https://github.com/rust-lang/crates.io/issues/2906
    cargo owner --add <username>
    
    # make sure everything looks good πŸ‘€ 
    cargo owner --list
    

    If there's anyone else you'd like to be able to publish the crate, feel free to add them to your publishing team, or as a user-owner. Consider that user-owners, as opposed to owners-via-team, can themselves edit the crate's owners, which could be desirable, or not, depending.

    In particular, it looks like @urschrei has been actively contributing to GH. Once you switch the publishing team, @urschrei (or anyone else) won't be able to publish until either they are added back to the publishing team or added as a user owner.

    Let me know if you have any questions, or you can review https://github.com/georust/meta/pull/21.

    opened by michaelkirk 2
  • Reconsider encode_coordinates interface

    Reconsider encode_coordinates interface

    Right now, encode_coordinates looks like:

    pub fn encode_coordinates(coordinates: &[[f64; 2]], precision: u32) -> Result<String, String> {
        ...
    }
    

    We don't need the entire slice at once, we just need anything that can iterate over coordinates:

    pub fn encode_coordinates<C>(coordinates: C, precision: u32) -> Result<String, String>
    where
        C: Iterator<Item=[f64; 2]>
    {
        ...
    }
    

    And maybe it makes sense to pull in the geo-types crate to reuse our common Coordinate construct:

    pub fn encode_coordinates<C, T>(coordinates: C, precision: u32) -> Result<String, String>
    where
        C: Iterator<Item=Coordinate<T>>
    {
        ...
    }
    
    opened by frewsxcv 2
  • Accept Vec and slice arguments to encode_polyline

    Accept Vec and slice arguments to encode_polyline

    This is both more flexible and potentially more efficient, since slices require a single pointer dereference, and Vecs require two.

    It also has the (potential) benefit of simplifying FFI interaction, since it's easier and more efficient to create slices than Vecs from pointers to data allocated outside Rust.

    opened by urschrei 2
  • Address Clippy warnings, simplify loops

    Address Clippy warnings, simplify loops

    Addresses Clippy warnings concerning potentially lossy conversions, and replaces String with &str in decode_polyline, which makes for a more pleasant API.

    opened by urschrei 1
  • Tests for invalid input strings, and bounds checks for coordinates

    Tests for invalid input strings, and bounds checks for coordinates

    This PR removes the last of the unwrap() calls (forgot to push that commit last time – sorry) and adds:

    • A test for invalid string input
    • Latitude and longitude bounds checking for the coordinate encoder, and a test.
    opened by urschrei 1
  • Basic error handling for en– and decoding

    Basic error handling for en– and decoding

    encode_coordinates() and decode_polyline() now cope with the possibility that a u32 can't be encoded as a char, or that your .nth() operation could fail because index is longer than str (the latter is unlikely, but here we are).

    This also means that your public functions now return Result types, which allows their consumers to be a bit more flexible.

    opened by urschrei 1
  • Fix rounding errors with coordinates close to each other

    Fix rounding errors with coordinates close to each other

    This adds a test and fix for a rounding error condition, when two coordinates are very close to each other, so that the difference is below precision.

    The current implementation would produce wrong characters, because the sign of the original subtraction would differ from the rounded subtraction.

    This PR changes the comparison to just use the sign of the rounded subtraction, see polyline.js for comparison.

    opened by niclashoyer 0
  • Switch to types from geo-types crate

    Switch to types from geo-types crate

    This PR switches the encode/decode API to use the Coordinate and LineString types from the geo-types crate and should fix #13.

    As this is my first PR for such a switch it might not be idiomatic. So I'm looking for feedback. The benchmarks and tests now include a .clone() for the input, because the iterator now owns the provided coordinates, instead of references to f64 pairs. Is there a way around this? Is this ok?

    This PR also contains #15 and #17.

    opened by niclashoyer 0
  • Adopt a similar strategy to proj for geo-types compatibility

    Adopt a similar strategy to proj for geo-types compatibility

    Although polyline also uses LineStrings, these can be primitively represented without too much trouble. Should we thus adopt a similar strategy to the proj crate, enabling geo-types compatibility by default but allowing a more simple option for consumers who don't want or need the overhead?

    opened by urschrei 0
Owner
GeoRust
A collection of geospatial tools and libraries written in Rust
GeoRust
A performant binary encoding for geographic data based on flatbuffers

FlatGeobuf A performant binary encoding for geographic data based on flatbuffers that can hold a collection of Simple Features including circular inte

FlatGeobuf 477 Jan 5, 2023
Rust crate for performing coordinate transforms

Synopsis A Rust crate use for performing coordinate transformations. The crate relies on nalgebra vectors to perform the coordinate transformations. C

Dave 25 Aug 20, 2022
An fast, offline reverse geocoder (>1,000 HTTP requests per second) in Rust.

Rust Reverse Geocoder A fast reverse geocoder in Rust. Inspired by Python reverse-geocoder. Links Crate 2.0.0 Docs 1.0.1 Docs Description rrgeo takes

Grant Miner 91 Dec 29, 2022
Geospatial primitives and algorithms for Rust

geo Geospatial Primitives, Algorithms, and Utilities The geo crate provides geospatial primitive types such as Point, LineString, and Polygon, and pro

GeoRust 989 Dec 29, 2022
Rust bindings for GDAL

gdal [] GDAL bindings for Rust. So far, you can: open a raster dataset for reading/writing get size and number of bands get/set projection and geo-tra

GeoRust 211 Jan 4, 2023
Rust bindings for the latest stable release of PROJ

PROJ Coordinate transformation via bindings to the PROJ v7.2.1 API. Two coordinate transformation operations are currently provided: projection (and i

GeoRust 96 Dec 21, 2022
Geohash for Rust

Rust-Geohash Rust-Geohash is a Rust library for Geohash algorithm. Ported from node-geohash module. Documentation Docs Check the API doc at docs.rs Li

GeoRust 74 Sep 8, 2022
Rust read/write support for well-known text (WKT)

wkt Rust read/write support for well-known text (WKT). License Licensed under either of Apache License, Version 2.0 (LICENSE-APACHE or http://www.apac

GeoRust 40 Dec 11, 2022
Geocoding library for Rust.

geocoding Rust utilities to enrich addresses, cities, countries, and landmarks with geographic coordinates through third-party geocoding web services.

GeoRust 55 Dec 12, 2022
Rust read/write support for GPS Exchange Format (GPX)

gpx gpx is a library for reading and writing GPX (GPS Exchange Format) files. It uses the primitives provided by geo-types to allow for storage of GPS

GeoRust 63 Dec 5, 2022
Geospatial primitives and algorithms for Rust

geo Geospatial Primitives, Algorithms, and Utilities The geo crate provides geospatial primitive types such as Point, LineString, and Polygon, and pro

GeoRust 990 Jan 1, 2023
Rust bindings for GEOS

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

GeoRust 75 Dec 11, 2022
Rust bindings for the latest stable release of PROJ

PROJ Coordinate transformation via bindings to the PROJ v7.2.1 API. Two coordinate transformation operations are currently provided: projection (and i

GeoRust 96 Dec 21, 2022
Spatial Data Structures for Rust

spade Documentation Using spade Examples Project state Performance License Spade (SPAtial DatastructurEs, obviously!) implements a few nifty data stru

Stefan Altmayer 195 Dec 21, 2022
Rust implementation of the Martinez-Rueda Polygon Clipping Algorithm

Boolean operations on geo shapes This is an implementation of the Martinez-Rueda Polygon Clipping Algorithm in rust to integrate smoothly into the alr

21re 70 Nov 28, 2022
Fast 2D Delaunay triangulation in Rust. A port of Delaunator.

delaunator-rs A very fast static 2D Delaunay triangulation library for Rust. A port of Delaunator. Documentation Example use delaunator::{Point, trian

Vladimir Agafonkin 123 Dec 20, 2022
port of MapBox's earcut triangulation code to Rust language

Earcutr This is a port of the MapBox company's Earcut computer code, which triangulates polygons. Please see https://github.com/mapbox/earcut for more

don bright 41 Dec 26, 2022
Rust bindings for GDAL

gdal [] GDAL bindings for Rust. So far, you can: open a raster dataset for reading/writing get size and number of bands get/set projection and geo-tra

GeoRust 208 Dec 27, 2022
Rust read/write support for GPS Exchange Format (GPX)

gpx gpx is a library for reading and writing GPX (GPS Exchange Format) files. It uses the primitives provided by geo-types to allow for storage of GPS

GeoRust 63 Dec 5, 2022