Crates.io | wkb |
lib.rs | wkb |
version | 0.7.1 |
source | src |
created_at | 2017-08-04 19:20:46.579848 |
updated_at | 2021-04-24 09:37:55.971296 |
description | Convert geo-types from georust to/from Well Known Binary |
homepage | |
repository | https://github.com/rory/rust-wkb |
max_upload_size | |
id | 26409 |
size | 68,141 |
rust-wkb
This crate provides functions to convert rust-geo
geometry types to and from Well Known Binary format, i.e. ISO 19125
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.