rust-postgis
An extension to rust-postgres, adds support for PostGIS.
- PostGIS type helper
- GCJ02 support (used offically in Mainland China)
- Tiny WKB (TWKB) support
- Optional serialization/deserialization support via serde
Usage
use ;
use ;
Handling NULL values:
let route = row.;
match route
Writing other geometry types into PostGIS
rust-postgis supports writing geometry types into PostGIS which implement the following traits:
Point,LineString, ...AsEwkbPoint,AsEwkbLineString, ...
See the TWKB implementation as an example.
An example for reading a TWKB geometry and writing it back as EWKB:
use twkb;
use LineString;
for row in &conn.query.unwrap
Unit tests
Unit tests which need a PostgreSQL connection are ignored by default.
To run the database tests, declare the connection in an environment variable DBCONN. Example:
export DBCONN=postgresql://user@localhost/testdb
Run the tests with
cargo test -- --ignored
Serialization with serde
This crate provides optional support for serializing and deserializing geometry types using serde. To enable this feature, add the following to your Cargo.toml:
[]
= { = "0.9.0", = ["serde"] }
With this feature enabled, all geometry types in ewkb and twkb modules will implement Serialize and Deserialize traits:
use Point;
use serde_json;
let point = Point ;
// Serialize to JSON
let json = to_string.unwrap;
println!;
// Deserialize from JSON
let deserialized: Point = from_str.unwrap;