#geo

wkb

Convert geo-types from georust to/from Well Known Binary

8 releases (breaking)

Uses old Rust 2015

0.7.1 Apr 24, 2021
0.7.0 Sep 23, 2020
0.6.0 Aug 29, 2020
0.5.0 Apr 25, 2020
0.1.0 Aug 4, 2017

#58 in Geospatial

Download history 196/week @ 2022-10-18 196/week @ 2022-10-25 123/week @ 2022-11-01 263/week @ 2022-11-08 337/week @ 2022-11-15 161/week @ 2022-11-22 90/week @ 2022-11-29 161/week @ 2022-12-06 244/week @ 2022-12-13 104/week @ 2022-12-20 71/week @ 2022-12-27 77/week @ 2023-01-03 131/week @ 2023-01-10 115/week @ 2023-01-17 185/week @ 2023-01-24 203/week @ 2023-01-31

642 downloads per month
Used in 5 crates

AGPL-3.0+

33KB
683 lines

rust-wkb

This crate provides functions to convert rust-geo geometry types to and from Well Known Binary format, i.e. ISO 19125

Examples

use geo_types::*;
use wkb::*;

let p: Geometry<f64> = Geometry::Point(Point::new(2., 4.));
let res = geom_to_wkb(&p);
assert_eq!(res, vec![1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 16, 64]);

You can also 'read' a Geometry from a std::io::Read:

use geo_types::*;
use wkb::*;

let bytes: Vec<u8> = vec![1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 16, 64];
let p: Geometry<f64> = wkb_to_geom(&mut bytes.as_slice()).unwrap();
assert_eq!(p, Geometry::Point(Point::new(2., 4.)));

Adding proper *Ext traits is planned.


lib.rs:

This crate provides functions to convert rust-geo geometry types to and from Well Known Binary format.

Examples

# extern crate geo_types;
# extern crate wkb;
# fn main() {
use geo_types::*;
use wkb::*;

let p: Geometry<f64> = Geometry::Point(Point::new(2., 4.));
let res = geom_to_wkb(&p).unwrap();
assert_eq!(res, vec![1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 16, 64]);
# }

You can also 'read' a Geometry from a std::io::Read:

# extern crate geo_types;
# extern crate wkb;
# fn main() {
use std::io::prelude::*;
use std::io::Cursor;
use geo_types::*;
use wkb::*;

let bytes: Vec<u8> = vec![1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 16, 64];
let mut bytes_cursor = Cursor::new(bytes);
let p = bytes_cursor.read_wkb().unwrap();
assert_eq!(p, Geometry::Point(Point::new(2., 4.)));
# }

.write_wkb(Geometry<Into<f64>>) works similar:

# extern crate geo_types;
# extern crate wkb;
# fn main() {
# use std::io::prelude::*;
# use geo_types::*;
# use wkb::*;

let mut bytes: Vec<u8> = vec![];
bytes.write_wkb(&Geometry::Point(Point::new(2_f64, 4.))).unwrap();
assert_eq!(bytes, vec![1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 16, 64]);
# }

Dependencies

~320KB