Skip to main content

DeserializeGeometry

Trait DeserializeGeometry 

Source
pub trait DeserializeGeometry: Sized {
    // Required method
    fn deserialize_geometry<T: GeometryTrait<T = f64>>(
        source: T,
        options: &GeometryOptions,
    ) -> Result<Self, GeometryError>;
}
Expand description

Converts a GeometryTrait value into Self.

Implement this trait for your own geometry types so they can be deserialized from any GIS source that exposes geometries through geo_traits. The source lets you look into an existing geometry via GeometryTrait, and this trait adds the other half, building Self from it, much as serde pairs Deserialize with Serialize.

§Errors

Returns a GeometryError if the source geometry cannot be interpreted as the target type under options.

§Example

use geoserde::de::{DeserializeGeometry, GeometryError, GeometryOptions};

struct Xy { x: f64, y: f64 }

impl DeserializeGeometry for Xy {
    fn deserialize_geometry<T: geo_traits::GeometryTrait<T = f64>>(
        source: T,
        _options: &GeometryOptions,
    ) -> Result<Self, GeometryError> {
        use geo_traits::{CoordTrait, GeometryType, PointTrait};
        match source.as_type() {
            GeometryType::Point(p) => {
                let c = p.coord().ok_or(GeometryError::custom("empty point"))?;
                Ok(Xy { x: c.x(), y: c.y() })
            }
            _ => Err(GeometryError::type_mismatch("Point", &source)),
        }
    }
}

Required Methods§

Source

fn deserialize_geometry<T: GeometryTrait<T = f64>>( source: T, options: &GeometryOptions, ) -> Result<Self, GeometryError>

Deserialize source into Self.

options tells which conversions between geometry types the caller allows. Impls may ignore the options that do not apply to Self.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl DeserializeGeometry for LineString

Available on crate feature geo-types only.
Source§

fn deserialize_geometry<T: GeometryTrait<T = f64>>( source: T, _options: &GeometryOptions, ) -> Result<Self, GeometryError>

Source§

impl DeserializeGeometry for MultiLineString

Available on crate feature geo-types only.
Source§

fn deserialize_geometry<T: GeometryTrait<T = f64>>( source: T, options: &GeometryOptions, ) -> Result<Self, GeometryError>

Source§

impl DeserializeGeometry for MultiPoint

Available on crate feature geo-types only.
Source§

fn deserialize_geometry<T: GeometryTrait<T = f64>>( source: T, options: &GeometryOptions, ) -> Result<Self, GeometryError>

Source§

impl DeserializeGeometry for Point

Available on crate feature geo-types only.
Source§

fn deserialize_geometry<T: GeometryTrait<T = f64>>( source: T, _options: &GeometryOptions, ) -> Result<Self, GeometryError>

Source§

impl DeserializeGeometry for Polygon

Available on crate feature geo-types only.
Source§

fn deserialize_geometry<T: GeometryTrait<T = f64>>( source: T, _options: &GeometryOptions, ) -> Result<Self, GeometryError>

Implementors§