TileBuilder

Struct TileBuilder 

Source
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:

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();

Implementations§

Source§

impl<W: TileWriter> TileBuilder<W>

Source

pub fn new(tile_writer: W, build_guide: BuildGuide) -> Self

Create a new Tile builder

Source

pub fn tile_writer(&self) -> &W

Get the tile writer

Source

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

Source

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

Source

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

Source

pub fn build_tiles(&mut self)

After adding all the source data, build all tiles into the tile writer

Trait Implementations§

Source§

impl<W: Debug + TileWriter> Debug for TileBuilder<W>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V