pub struct Feature { /* private fields */ }
Expand description
A Feature contains map geometry with related metadata.
A new Feature can be obtained with Layer.into_feature. After optionally adding an ID and tags, retrieve the Layer with the Feature added by calling Feature.into_layer.
§Example
use mvt::{GeomEncoder, GeomType, Tile};
use pointy::Transform;
let tile = Tile::new(4096);
let layer = tile.create_layer("First Layer");
let geom_data = GeomEncoder::new(GeomType::Point)
.point(1.0, 2.0)?
.point(7.0, 6.0)?
.encode()?;
let feature = layer.into_feature(geom_data);
// ...
// add any tags or ID to the feature
// ...
let layer = feature.into_layer();
Implementations§
Source§impl Feature
impl Feature
Sourcepub fn into_layer(self) -> Layer
pub fn into_layer(self) -> Layer
Complete the feature, returning ownership of the layer.
Examples found in repository?
examples/simple.rs (line 17)
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}
Sourcepub fn set_id(&mut self, id: u64)
pub fn set_id(&mut self, id: u64)
Set the feature ID.
Examples found in repository?
examples/simple.rs (line 15)
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}
Get number of tags (count).
Sourcepub fn add_tag_string(&mut self, key: &str, val: &str)
pub fn add_tag_string(&mut self, key: &str, val: &str)
Add a tag of string type.
Examples found in repository?
examples/simple.rs (line 16)
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}
Sourcepub fn add_tag_double(&mut self, key: &str, val: f64)
pub fn add_tag_double(&mut self, key: &str, val: f64)
Add a tag of double type.
Sourcepub fn add_tag_float(&mut self, key: &str, val: f32)
pub fn add_tag_float(&mut self, key: &str, val: f32)
Add a tag of float type.
Sourcepub fn add_tag_int(&mut self, key: &str, val: i64)
pub fn add_tag_int(&mut self, key: &str, val: i64)
Add a tag of int type.
Sourcepub fn add_tag_uint(&mut self, key: &str, val: u64)
pub fn add_tag_uint(&mut self, key: &str, val: u64)
Add a tag of uint type.
Sourcepub fn add_tag_sint(&mut self, key: &str, val: i64)
pub fn add_tag_sint(&mut self, key: &str, val: i64)
Add a tag of sint type.
Sourcepub fn add_tag_bool(&mut self, key: &str, val: bool)
pub fn add_tag_bool(&mut self, key: &str, val: bool)
Add a tag of bool type.
Auto Trait Implementations§
impl !Freeze for Feature
impl RefUnwindSafe for Feature
impl Send for Feature
impl Sync for Feature
impl Unpin for Feature
impl UnwindSafe for Feature
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more