pub struct TileBuilder<W: TileWriter = LocalTileWriter> { /* private fields */ }Expand description
§The Tile Builder
§Description
The TileBuilder creates tiles for the user given any source reader that implements FeatureReader
Create vector tiles, raster tiles, or gridded tiles.
Store as Mapbox Vector Tiles or Open Vector Tiles. Utilizes the TileWriter trait to write the data to.
Supports storing as a folder structure or a PMTiles (with gzip compression if enabled)
§Usage
The methods you have access to:
TileBuilder::new: Create a new TileBuilderTileBuilder::tile_writer: Get the tile writerTileBuilder::add_vector_source: Add a vector source to tile-izeTileBuilder::add_grid_source: Add data that will be gridded like raster data but float precision pointsTileBuilder::build_tiles: After adding all the source data, build all tiles into the tile writer
The Tile Writers this library supports:
§Writing WM projection tiles as Mapbox Vector Tiles to a PMTiles file
use gistools::{
data_structures::TileStoreOptions,
parsers::{BufferWriter, FileReader},
readers::JSONReader,
util::CompressionFormat,
writers::{
BuildGuide, PMTilesWriter, TileBuilder, LayerGuide,
VectorLayerGuide, BaseLayer
}
};
use serde::{Deserialize, Serialize};
use s2_tilejson::{Metadata, MetadataBuilder, DrawType};
use open_vector_tile::Extent;
use s2json::{MValue, MValueCompatible, Properties, Projection};
use std::{path::PathBuf, collections::BTreeMap};
#[derive(Debug, Default, Clone, MValueCompatible, PartialEq, Serialize, Deserialize)]
#[serde(default)]
struct PointProps {
id: i64,
}
#[derive(Debug, Default, Clone, MValueCompatible, PartialEq, Serialize, Deserialize)]
#[serde(default)]
struct LineProps {
linename: String,
}
#[derive(Debug, Default, Clone, MValueCompatible, PartialEq, Serialize, Deserialize)]
#[serde(default)]
struct PolyProps {
poly3d: bool,
}
// using a buffer writer for example but ideally you are using a FileWriter
let tmp_buffer_writer = BufferWriter::new(vec![]);
let pm_writer = PMTilesWriter::new(tmp_buffer_writer, CompressionFormat::None);
let build_guide = BuildGuide {
projection: Projection::WG,
build_indices: true,
attributions: BTreeMap::from([("Satellite Data".into(), "https://example.com".into())]),
layer_guides: vec![
// add points
LayerGuide::Vector(VectorLayerGuide {
extent: Extent::Extent4096,
draw_types: vec![DrawType::Points, DrawType::Points3D],
shape: Some((&MValue::from(PointProps::default())).into()),
base: BaseLayer {
description: Some("Points Vector Layer".into()),
source_name: "all_features".into(),
layer_name: "points".into(),
},
vector_guide: TileStoreOptions { maxzoom: Some(4), ..Default::default() },
..Default::default()
}),
// add lines
LayerGuide::Vector(VectorLayerGuide {
extent: Extent::Extent4096,
draw_types: vec![DrawType::Lines, DrawType::Lines3D],
shape: Some((&MValue::from(LineProps::default())).into()),
base: BaseLayer {
description: Some("Lines Vector Layer".into()),
source_name: "all_features".into(),
layer_name: "lines".into(),
},
vector_guide: TileStoreOptions { maxzoom: Some(4), ..Default::default() },
..Default::default()
}),
// add polys
LayerGuide::Vector(VectorLayerGuide {
extent: Extent::Extent4096,
draw_types: vec![DrawType::Polygons, DrawType::Polygons3D],
shape: Some((&MValue::from(PolyProps::default())).into()),
base: BaseLayer {
description: Some("Polygons Vector Layer".into()),
source_name: "all_features".into(),
layer_name: "polys".into(),
},
vector_guide: TileStoreOptions { maxzoom: Some(4), ..Default::default() },
..Default::default()
}),
],
..Default::default()
};
let mut tile_builder = TileBuilder::new(pm_writer, build_guide);
// add json features
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path = path.join("tests/writers/fixtures/all-features.json");
let reader: JSONReader<FileReader, (), Properties, Properties> =
JSONReader::new(FileReader::from(path));
tile_builder.add_vector_source("all_features".into(), reader, None, None);
// build
tile_builder.build_tiles();§Links
Implementations§
Source§impl<W: TileWriter> TileBuilder<W>
impl<W: TileWriter> TileBuilder<W>
Sourcepub fn new(tile_writer: W, build_guide: BuildGuide) -> Self
pub fn new(tile_writer: W, build_guide: BuildGuide) -> Self
Create a new Tile builder
Sourcepub fn tile_writer(&self) -> &W
pub fn tile_writer(&self) -> &W
Get the tile writer
Sourcepub fn add_vector_source<M: Clone + HasLayer, P: MValueCompatible, D: MValueCompatible, T: FeatureReader<M, P, D>>(
&mut self,
source_name: String,
reader: T,
on_source_feature: Option<OnFeature<M, P, D>>,
on_layer_feature: Option<&Vec<LayerHandler<M, P, D>>>,
)
pub fn add_vector_source<M: Clone + HasLayer, P: MValueCompatible, D: MValueCompatible, T: FeatureReader<M, P, D>>( &mut self, source_name: String, reader: T, on_source_feature: Option<OnFeature<M, P, D>>, on_layer_feature: Option<&Vec<LayerHandler<M, P, D>>>, )
Add a vector source to tile-ize
Sourcepub fn add_raster_source<M: Clone, P: MValueCompatible, D: MValueCompatible, T: FeatureReader<M, P, D>>(
_source_name: String,
_reader: T,
_on_feature: Option<OnFeature<M, P, D>>,
)
pub fn add_raster_source<M: Clone, P: MValueCompatible, D: MValueCompatible, T: FeatureReader<M, P, D>>( _source_name: String, _reader: T, _on_feature: Option<OnFeature<M, P, D>>, )
Add vector points with RGBA attributes to build raster tiles
Sourcepub fn add_grid_source<M: Clone, P: MValueCompatible, D: MValueCompatible, T: FeatureReader<M, P, D>>(
_source_name: String,
_reader: T,
_on_feature: Option<OnFeature<M, P, D>>,
)
pub fn add_grid_source<M: Clone, P: MValueCompatible, D: MValueCompatible, T: FeatureReader<M, P, D>>( _source_name: String, _reader: T, _on_feature: Option<OnFeature<M, P, D>>, )
Add data that will be gridded like raster data but float precision points
Sourcepub fn build_tiles(&mut self)
pub fn build_tiles(&mut self)
After adding all the source data, build all tiles into the tile writer
Trait Implementations§
Auto Trait Implementations§
impl<W> Freeze for TileBuilder<W>where
W: Freeze,
impl<W = LocalTileWriter> !RefUnwindSafe for TileBuilder<W>
impl<W> Send for TileBuilder<W>where
W: Send,
impl<W = LocalTileWriter> !Sync for TileBuilder<W>
impl<W> Unpin for TileBuilder<W>where
W: Unpin,
impl<W = LocalTileWriter> !UnwindSafe for TileBuilder<W>
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more