geolith 0.1.1

Shared library of the geolith builders: source readers, conflation, admin areas, tile encoding and the PMTiles and MBTiles writers
Documentation
//! Intermediate tile feature representation between source reading and MVT encoding.

use std::sync::Arc;

use serde::{Deserialize, Serialize};

use crate::layer::Layer;

/// MVT tile extent (coordinate space).
pub const TILE_EXTENT: u32 = 4096;

/// Buffer pixels added around each tile for label/line overflow.
pub const BUFFER_PIXELS: f64 = 4.0;

/// Geometry type for tile features.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[repr(u8)]
pub enum GeomType {
    /// Single point or multipoint.
    Point = 1,
    /// Linestring or multilinestring.
    Line = 2,
    /// Polygon or multipolygon.
    Polygon = 3,
}

/// A single key-value property on a tile feature.
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PropValue {
    /// String property.
    Str(String),
    /// 64-bit float property.
    F64(f64),
    /// 64-bit signed integer property.
    I64(i64),
    /// 64-bit unsigned integer property.
    U64(u64),
    /// Boolean property.
    Bool(bool),
}

/// A processed feature ready for tile encoding.
///
/// Coordinates are in tile-local space [0, `TILE_EXTENT`] after projection
/// and clipping. Properties are key-value pairs that become MVT tags.
///
/// Properties use `Arc` for copy-on-write sharing — all tile features
/// derived from the same source feature share one allocation until
/// mutation (e.g. height quantization) triggers a clone.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TileFeature {
    /// Which output layer this feature belongs to.
    pub layer: Layer,
    /// Optional feature ID (from Overture or generated).
    pub id: u64,
    /// Geometry type.
    pub geom_type: GeomType,
    /// Encoded geometry commands in MVT format (pre-encoded).
    ///
    /// This is the raw `repeated uint32 geometry` from the MVT spec.
    /// Pre-encoding avoids a second pass during tile assembly.
    pub geometry: Vec<u32>,
    /// Feature properties as key-value pairs (Arc-shared for COW).
    pub properties: Arc<Vec<(String, PropValue)>>,
    /// Sort key for ordering within a layer (lower = drawn first / underneath).
    pub sort_key: i32,
}