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 order_audit;
15pub mod packed;
16pub mod recommend;
17pub mod report;
18
19#[cfg(test)]
20mod test_support;
21
22use anyhow::Result;
23
24pub use analysis::inspect::InspectReport;
25pub use diff::DiffReport;
26pub use doctor::DoctorReport;
27pub use order_audit::OrderAuditReport;
28pub use loader::DataSource;
29pub use packed::PackedTileset;
30pub use recommend::Recommendations;
31
32/// Analyze a GeoParquet or STT input and produce build recommendations.
33pub fn recommend_for(source: &DataSource) -> Result<Recommendations> {
34    let data = loader::load_data(source)?;
35    let spatial = analysis::spatial::analyze(&data)?;
36    let temporal = analysis::temporal::analyze(&data)?;
37    let geometry = analysis::geometry::analyze(&data)?;
38    // Measured sample encoding at build defaults; None (formula fallback)
39    // when the sample is too small.
40    let measured = measure::measure_sample(&data.sample, &measure::MeasureSettings::default())?;
41    let density = analysis::density::analyze(&data, &spatial, &temporal, measured.as_ref())?;
42    let result = analysis::AnalysisResult {
43        source: source.display_name(),
44        feature_count: data.features.len(),
45        bounds: data.bounds,
46        spatial,
47        temporal,
48        geometry,
49        density,
50        measured,
51    };
52    // Evidence-based flag advisors (quantize, temporal, layout, budget) —
53    // attached to the recommendations; lossy entries are surface-only.
54    let advice = advisors::run_all(&result, &data)?;
55    Ok(recommend::generate_recommendations(&result, advice))
56}