pub struct S2TilesReader<R: Reader> { /* private fields */ }Expand description
§S2 Tiles Reader
§Description
An S2 Tile Reader to store tile and metadata in a cloud optimized format. Similar to PMTiles but simplified to have as few features as possible.
Reads either a Web Mercator tile or an S2 tile to the folder location given its (zoom, x, y) or (face, zoom, x, y) coordinates.
Reads data via the S2Tiles specification.
§Usage
S2TilesReader utilizes any struct that implements the Reader trait.
Options are crate::parsers::BufferReader, crate::parsers::FileReader, crate::parsers::MMapReader, and crate::parsers::FetchReader.
The methods you have access to:
S2TilesReader::new: Create a new S2TilesReaderS2TilesReader::get_metadata: Get the metadata of the archiveS2TilesReader::has_tile_wm: Check if a WM tile exists in the archiveS2TilesReader::has_tile_s2: Check if an S2 tile exists in the archiveS2TilesReader::get_tile_wm: Get the bytes of the tile at the given (zoom, x, y) coordinatesS2TilesReader::get_tile_s2: Get the bytes of the tile at the given (face, zoom, x, y) coordinates
use gistools::{parsers::FileReader, readers::S2TilesReader};
use std::path::PathBuf;
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/writers/fixtures/example.s2tiles");
let file_reader = FileReader::new(path).unwrap();
let mut reader = S2TilesReader::new(file_reader, None);
smol::block_on(async {
// get the metadata
let metadata = reader.get_metadata().await;
// S2 specific functions
assert!(reader.has_tile_s2(0.into(), 0, 0, 0).await);
let tile = reader.get_tile_s2(0.into(), 0, 0, 0).await;
// WM functions
assert!(reader.has_tile_wm(0, 0, 0).await);
let tile = reader.get_tile_wm(0, 0, 0).await;
});§Links
- https://github.com/Open-S2/s2tiles/blob/master/s2tiles-spec/1.0.0/README.md
Implementations§
Source§impl<R: Reader> S2TilesReader<R>
impl<R: Reader> S2TilesReader<R>
Sourcepub fn new(reader: R, max_size: Option<usize>) -> Self
pub fn new(reader: R, max_size: Option<usize>) -> Self
Create a new S2TilesReader
§Parameters
reader- the input reader to parse frommax_size- the max size of the cache before dumping old data. Defaults to 20.
Sourcepub async fn get_metadata(&mut self) -> Metadata
pub async fn get_metadata(&mut self) -> Metadata
Sourcepub async fn get_tile_s2(
&mut self,
face: Face,
zoom: u8,
x: u32,
y: u32,
) -> Option<Vec<u8>>
pub async fn get_tile_s2( &mut self, face: Face, zoom: u8, x: u32, y: u32, ) -> Option<Vec<u8>>
Get the bytes of the tile at the given (face, zoom, x, y) coordinates
§Parameters
face: the Open S2 projection facezoom: the zoom level of the tilex: the x coordinate of the tiley: the y coordinate of the tile
§Returns
The bytes of the tile at the given (face, zoom, x, y) coordinates, or undefined if the tile does not exist in the archive.
Trait Implementations§
Auto Trait Implementations§
impl<R> Freeze for S2TilesReader<R>where
R: Freeze,
impl<R> RefUnwindSafe for S2TilesReader<R>where
R: RefUnwindSafe,
impl<R> Send for S2TilesReader<R>where
R: Send,
impl<R> Sync for S2TilesReader<R>where
R: Sync,
impl<R> Unpin for S2TilesReader<R>where
R: Unpin,
impl<R> UnwindSafe for S2TilesReader<R>where
R: UnwindSafe,
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
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>
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>
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