#geographic #gis #adapter #file-format #features #serialization #point

geoserde

Adapter between geographic features and GIS files

13 releases (4 breaking)

0.5.2 Jun 9, 2024
0.5.1 Jun 5, 2024
0.5.0 May 26, 2024
0.4.1 Feb 18, 2024
0.1.3 Dec 14, 2023

#79 in Geospatial

Download history 36/week @ 2024-02-25 7/week @ 2024-03-03 30/week @ 2024-03-10 2/week @ 2024-03-17 28/week @ 2024-03-31 2/week @ 2024-04-07 7/week @ 2024-05-19 211/week @ 2024-05-26 171/week @ 2024-06-02 260/week @ 2024-06-09

649 downloads per month
Used in fgbfile

MIT license

54KB
1.5K SLoC

geoserde

crates.io docs.rs

Geoserde is an adapter between geographic feature structs and GIS file formats.

See API documantation with some examples.

Licensed under the MIT License.


lib.rs:

Geoserde is an adapter between geographic feature structs and GIS file formats.

Getting started

cargo add geoserde

Cargo features

  • geozero - Implement geoserde sink for geozero processors. Enabled by default.

Examples

use geo_types::Point;
use geoserde::FeatureSerializer;
use geozero::geojson::GeoJsonWriter;
use serde::Serialize;

// Print two features to the console in GeoJson format
fn main() -> anyhow::Result<()> {
    // If you want to write to a file, use BufWriter<File> instead
    let mut buf = vec![];

    // Any format that has an implementation of geozero::FeatureProcessor can be used,
    // such as wkt, shp, fgb, etc. See also https://docs.rs/geozero/latest/geozero/
    let mut geojson = GeoJsonWriter::new(&mut buf);

    // Serialize features to GeoJson format
    let mut ser = FeatureSerializer::new(&mut geojson);
    my_features().serialize(&mut ser)?;

    println!("{}", std::str::from_utf8(&buf)?);
    Ok(())
}

// Create feature array
fn my_features() -> impl Serialize {
    [
        Station {
            name: "King's Cross",
            europe: true,
            loc: Point::new(51.5321, -0.1233),
        },
        Station {
            name: "Tokyo",
            europe: false,
            loc: Point::new(139.7661, 35.6812),
        },
    ]
}

// Geographic feature
#[derive(Serialize)]
struct Station {
    // Property
    name: &'static str,

    // Property
    europe: bool,

    // Geometry
    loc: Point,
}

Dependencies

~1.9–2.7MB
~58K SLoC