Skip to content

Commit

Permalink
Move TileIdMethod from tinymvt to nusamai (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscorn authored Oct 24, 2024
1 parent d95e938 commit b02a635
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nusamai/src/sink/mvt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

mod slice;
mod tags;
mod tileid;

use std::{
convert::Infallible,
Expand All @@ -21,7 +22,8 @@ use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use slice::slice_cityobj_geoms;
use tags::convert_properties;
use tinymvt::{geometry::GeometryEncoder, tag::TagsEncoder, tileid::TileIdMethod, vector_tile};
use tileid::TileIdMethod;
use tinymvt::{geometry::GeometryEncoder, tag::TagsEncoder, vector_tile};

use crate::{
get_parameter_value,
Expand Down
34 changes: 34 additions & 0 deletions nusamai/src/sink/mvt/tileid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use tinymvt::tileid::hilbert;

/// Tile ID calculation method
#[derive(Clone, Copy, Debug)]
pub enum TileIdMethod {
/// Tile ID based on Hilbert curve (compliant with PMTiles)
Hilbert,
}

impl TileIdMethod {
pub fn zxy_to_id(&self, z: u8, x: u32, y: u32) -> u64 {
match self {
TileIdMethod::Hilbert => hilbert::zxy_to_id(z, x, y),
}
}

pub fn id_to_zxy(&self, tile_id: u64) -> (u8, u32, u32) {
match self {
TileIdMethod::Hilbert => hilbert::id_to_zxy(tile_id),
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn hilbert() {
let tile_id_method = TileIdMethod::Hilbert;
assert_eq!(tile_id_method.zxy_to_id(2, 1, 1), 7);
assert_eq!(tile_id_method.id_to_zxy(7), (2, 1, 1));
}
}

0 comments on commit b02a635

Please sign in to comment.