Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move TileIdMethod from tinymvt to plateau-gis-converter #675

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}