Skip to main content

stt_optimize/
lib.rs

1//! stt-optimize as a library.
2//!
3//! `stt-build --auto` calls into [`recommend_for`] to pick zoom levels and
4//! a temporal bucket from an input file before building.
5//! The `stt-optimize` CLI (a binary in the `spatiotemporal-tiles` facade
6//! crate) is a thin wrapper around the same functions.
7
8pub mod advisors;
9pub mod analysis;
10pub mod diff;
11pub mod doctor;
12pub mod loader;
13pub mod measure;
14pub mod packed;
15pub mod recommend;
16pub mod report;
17
18use anyhow::Result;
19
20pub use analysis::inspect::InspectReport;
21pub use diff::DiffReport;
22pub use doctor::DoctorReport;
23pub use loader::DataSource;
24pub use packed::PackedTileset;
25pub use recommend::Recommendations;
26
27/// Analyze a GeoParquet or STT input and produce build recommendations.
28pub fn recommend_for(source: &DataSource) -> Result<Recommendations> {
29    let data = loader::load_data(source)?;
30    let spatial = analysis::spatial::analyze(&data)?;
31    let temporal = analysis::temporal::analyze(&data)?;
32    let geometry = analysis::geometry::analyze(&data)?;
33    // Measured sample encoding at build defaults; None (formula fallback)
34    // when the sample is too small.
35    let measured = measure::measure_sample(&data.sample, &measure::MeasureSettings::default())?;
36    let density = analysis::density::analyze(&data, &spatial, &temporal, measured.as_ref())?;
37    let result = analysis::AnalysisResult {
38        source: source.display_name(),
39        feature_count: data.features.len(),
40        bounds: data.bounds,
41        spatial,
42        temporal,
43        geometry,
44        density,
45        measured,
46    };
47    // Evidence-based flag advisors (quantize, temporal, layout, budget) —
48    // attached to the recommendations; lossy entries are surface-only.
49    let advice = advisors::run_all(&result, &data)?;
50    Ok(recommend::generate_recommendations(&result, advice))
51}