GeomEncoder

Struct GeomEncoder 

Source
pub struct GeomEncoder<F>
where F: Float,
{ /* private fields */ }
Expand description

Encoder for Feature geometry.

This can consist of Point, Linestring or Polygon data.

§Example

let geom_data = GeomEncoder::new(GeomType::Point)
    .point(0.0, 0.0)?
    .point(10.0, 0.0)?
    .encode()?;

Implementations§

Source§

impl<F> GeomEncoder<F>
where F: Float,

Source

pub fn new(geom_tp: GeomType) -> Self

Create a new geometry encoder.

  • geom_tp Geometry type.
Examples found in repository?
examples/simple.rs (line 7)
3fn main() -> Result<(), Error> {
4    let mut tile = Tile::new(4096);
5    let layer = tile.create_layer("First Layer");
6    // NOTE: normally, the Transform would come from MapGrid::tile_transform
7    let b = GeomEncoder::new(GeomType::Linestring)
8        .point(0.0, 0.0)?
9        .point(1024.0, 0.0)?
10        .point(1024.0, 2048.0)?
11        .point(2048.0, 2048.0)?
12        .point(2048.0, 4096.0)?
13        .encode()?;
14    let mut feature = layer.into_feature(b);
15    feature.set_id(1);
16    feature.add_tag_string("key", "value");
17    let layer = feature.into_layer();
18    tile.add_layer(layer)?;
19    let data = tile.to_bytes()?;
20    println!("encoded {} bytes: {:?}", data.len(), data);
21    Ok(())
22}
Source

pub fn bbox(self, bbox: BBox<F>) -> Self

Add a bounding box

Source

pub fn transform(self, transform: Transform<F>) -> Self

Add a transform

Source

pub fn point(self, x: F, y: F) -> Result<Self, Error>

Add a point, taking ownership (for method chaining).

Examples found in repository?
examples/simple.rs (line 8)
3fn main() -> Result<(), Error> {
4    let mut tile = Tile::new(4096);
5    let layer = tile.create_layer("First Layer");
6    // NOTE: normally, the Transform would come from MapGrid::tile_transform
7    let b = GeomEncoder::new(GeomType::Linestring)
8        .point(0.0, 0.0)?
9        .point(1024.0, 0.0)?
10        .point(1024.0, 2048.0)?
11        .point(2048.0, 2048.0)?
12        .point(2048.0, 4096.0)?
13        .encode()?;
14    let mut feature = layer.into_feature(b);
15    feature.set_id(1);
16    feature.add_tag_string("key", "value");
17    let layer = feature.into_layer();
18    tile.add_layer(layer)?;
19    let data = tile.to_bytes()?;
20    println!("encoded {} bytes: {:?}", data.len(), data);
21    Ok(())
22}
Source

pub fn add_point(&mut self, x: F, y: F) -> Result<(), Error>

Add a point.

Source

pub fn complete_geom(&mut self) -> Result<(), Error>

Complete the current geometry (for multilinestring / multipolygon).

Source

pub fn complete(self) -> Result<Self, Error>

Complete the current geometry (for multilinestring / multipolygon).

Source

pub fn encode(self) -> Result<GeomData, Error>

Encode the geometry data, consuming the encoder.

Examples found in repository?
examples/simple.rs (line 13)
3fn main() -> Result<(), Error> {
4    let mut tile = Tile::new(4096);
5    let layer = tile.create_layer("First Layer");
6    // NOTE: normally, the Transform would come from MapGrid::tile_transform
7    let b = GeomEncoder::new(GeomType::Linestring)
8        .point(0.0, 0.0)?
9        .point(1024.0, 0.0)?
10        .point(1024.0, 2048.0)?
11        .point(2048.0, 2048.0)?
12        .point(2048.0, 4096.0)?
13        .encode()?;
14    let mut feature = layer.into_feature(b);
15    feature.set_id(1);
16    feature.add_tag_string("key", "value");
17    let layer = feature.into_layer();
18    tile.add_layer(layer)?;
19    let data = tile.to_bytes()?;
20    println!("encoded {} bytes: {:?}", data.len(), data);
21    Ok(())
22}

Trait Implementations§

Source§

impl<F> Default for GeomEncoder<F>
where F: Float + Default,

Source§

fn default() -> GeomEncoder<F>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<F> Freeze for GeomEncoder<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for GeomEncoder<F>
where F: RefUnwindSafe,

§

impl<F> Send for GeomEncoder<F>
where F: Send,

§

impl<F> Sync for GeomEncoder<F>
where F: Sync,

§

impl<F> Unpin for GeomEncoder<F>
where F: Unpin,

§

impl<F> UnwindSafe for GeomEncoder<F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.