Skip to main content

tylertoo_core/
lib.rs

1#![recursion_limit = "256"]
2//! Core library for GeoParquet multi-resolution overviews and PMTiles export.
3//!
4//! The product pipeline lives in [`overview`]: convert a (gpio-sorted)
5//! GeoParquet file into a level-banded overview GeoParquet file
6//! ([`overview::convert`]), validate it against the spec
7//! ([`overview::check`]), and export it to a PMTiles vector-tile archive
8//! ([`overview::export`]).
9//!
10//! The remaining top-level modules are shared infrastructure the overview
11//! pipeline builds on: Arrow/Parquet geometry decoding ([`batch_processor`],
12//! [`wkb`], [`covering`]), tile math ([`tile`], [`world_coord`]), geometry
13//! clipping ([`clip`], [`ioverlay_clip`], [`sutherland_hodgman`]), MVT
14//! encoding ([`mvt`]), and the PMTiles v3 writer ([`pmtiles_writer`],
15//! [`compression`], [`dedup`]).
16//!
17//! The legacy per-tile pipeline (`pipeline`, `Converter`) was removed in
18//! favor of the overview pipeline; see `context/ARCHITECTURE.md` for the
19//! decision record. The one-shot GeoParquet → PMTiles UX survives as the
20//! CLI `tiles` facade, which chains overview convert → export-pmtiles
21//! through a temporary file.
22//!
23//! # Memory Profiling
24//!
25//! Build with `--features dhat-heap` to enable heap profiling with dhat.
26//! When enabled, the program will write `dhat-heap.json` on exit which can
27//! be analyzed at <https://nnethercote.github.io/dh_view/dh_view.html>
28
29// dhat global allocator - must be at crate root
30#[cfg(feature = "dhat-heap")]
31#[global_allocator]
32static ALLOC: dhat::Alloc = dhat::Alloc;
33
34use thiserror::Error;
35
36// Include the protobuf-generated code
37pub mod vector_tile {
38    include!(concat!(env!("OUT_DIR"), "/vector_tile.rs"));
39}
40
41pub mod batch_processor;
42pub mod clip;
43pub mod compression;
44pub mod covering;
45pub mod decode;
46pub mod dedup;
47pub mod fs_probe;
48pub mod input;
49pub mod input_set;
50pub mod ioverlay_clip;
51pub mod mvt;
52pub mod overview;
53pub mod pmtiles_writer;
54pub mod pyramid;
55pub mod quality;
56pub mod sutherland_hodgman;
57pub mod tile;
58pub mod wkb;
59pub mod world_coord;
60
61// Re-export Compression from compression module for public API
62pub use compression::Compression;
63// Re-export StreamingPmtilesWriter and related types
64pub use pmtiles_writer::{StreamingPmtilesWriter, StreamingWriteStats};
65// Re-export CRS validation for public API
66pub use quality::{extract_crs, validate_wgs84, CrsInfo};
67
68/// Errors that can occur while reading GeoParquet or writing PMTiles.
69#[derive(Error, Debug)]
70pub enum Error {
71    #[error("Failed to read GeoParquet file: {0}")]
72    GeoParquetRead(String),
73
74    #[error("Failed to write PMTiles: {0}")]
75    PMTilesWrite(String),
76
77    #[error("Failed to read PMTiles: {0}")]
78    PMTilesRead(String),
79
80    #[error("Invalid geometry at feature {feature_id}: {reason}")]
81    InvalidGeometry { feature_id: usize, reason: String },
82
83    #[error("MVT encoding failed: {0}")]
84    MvtEncoding(String),
85
86    #[error("Invalid configuration: {0}")]
87    InvalidConfig(String),
88
89    #[error("IO error: {0}")]
90    Io(#[from] std::io::Error),
91}
92
93pub type Result<T> = std::result::Result<T, Error>;