From 83f9dc870c15493c62a1aaf08802d11c4c11f82c Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sun, 5 Apr 2026 17:26:06 +0200 Subject: implement OsmAnd/MbTiles in python interface --- hittekaart-py/hittekaart_py/hittekaart_py.pyi | 5 ++++- hittekaart-py/src/lib.rs | 32 ++++++++++++++++++--------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/hittekaart-py/hittekaart_py/hittekaart_py.pyi b/hittekaart-py/hittekaart_py/hittekaart_py.pyi index 0efe011..b3d110c 100644 --- a/hittekaart-py/hittekaart_py/hittekaart_py.pyi +++ b/hittekaart-py/hittekaart_py/hittekaart_py.pyi @@ -14,7 +14,10 @@ class Storage: def Folder(path: bytes) -> "Storage": ... @staticmethod - def Sqlite(path: bytes) -> "Storage": ... + def OsmAnd(path: bytes) -> "Storage": ... + + @staticmethod + def MbTiles(path: bytes) -> "Storage": ... class HeatmapRenderer: diff --git a/hittekaart-py/src/lib.rs b/hittekaart-py/src/lib.rs index c0f3f6c..7a88bab 100644 --- a/hittekaart-py/src/lib.rs +++ b/hittekaart-py/src/lib.rs @@ -87,7 +87,8 @@ impl Track { #[derive(Debug, Clone, PartialEq, Eq)] enum StorageType { Folder(PathBuf), - Sqlite(PathBuf), + OsmAnd(PathBuf), + MbTiles(PathBuf), } /// Represents a storage target. @@ -113,22 +114,28 @@ impl Storage { Storage(StorageType::Folder(path.into())) } - /// Output to the given SQLite file. - /// - /// This will create a single table 'tiles' with the columns 'zoom', 'x', 'y' and 'data'. + /// Output to the given SQLite file in a OsmAnd compatible format. /// /// Note that you cannot "append" to an existing database, it must be a non-existing file. #[staticmethod] - #[pyo3(name = "Sqlite")] - fn sqlite(path: &[u8]) -> Self { + #[pyo3(name = "OsmAnd")] + fn osmand(path: &[u8]) -> Self { + let path = OsStr::from_bytes(path); + Storage(StorageType::OsmAnd(path.into())) + } + + #[staticmethod] + #[pyo3(name = "MbTiles")] + fn mbtiles(path: &[u8]) -> Self { let path = OsStr::from_bytes(path); - Storage(StorageType::Sqlite(path.into())) + Storage(StorageType::MbTiles(path.into())) } fn __repr__(&self) -> String { match self.0 { StorageType::Folder(ref path) => format!("", path.display()), - StorageType::Sqlite(ref path) => format!("", path.display()), + StorageType::OsmAnd(ref path) => format!("", path.display()), + StorageType::MbTiles(ref path) => format!("", path.display()), } } } @@ -140,8 +147,13 @@ impl Storage { let storage = hittekaart::storage::Folder::new(path.clone()); Ok(Box::new(storage)) } - StorageType::Sqlite(ref path) => { - let storage = hittekaart::storage::Sqlite::connect(path.clone()) + StorageType::OsmAnd(ref path) => { + let storage = hittekaart::storage::OsmAnd::open(path.clone()) + .map_err(|e| err_to_py(&e))?; + Ok(Box::new(storage)) + } + StorageType::MbTiles(ref path) => { + let storage = hittekaart::storage::MbTiles::open(path.clone()) .map_err(|e| err_to_py(&e))?; Ok(Box::new(storage)) } -- cgit v1.2.3