Skip to main content

geolith/tile/
feature.rs

1//! Intermediate tile feature representation between source reading and MVT encoding.
2
3use std::sync::Arc;
4
5use serde::{Deserialize, Serialize};
6
7use crate::layer::Layer;
8
9/// MVT tile extent (coordinate space).
10pub const TILE_EXTENT: u32 = 4096;
11
12/// Buffer pixels added around each tile for label/line overflow.
13pub const BUFFER_PIXELS: f64 = 4.0;
14
15/// Geometry type for tile features.
16#[non_exhaustive]
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
18#[repr(u8)]
19pub enum GeomType {
20    /// Single point or multipoint.
21    Point = 1,
22    /// Linestring or multilinestring.
23    Line = 2,
24    /// Polygon or multipolygon.
25    Polygon = 3,
26}
27
28/// A single key-value property on a tile feature.
29#[non_exhaustive]
30#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
31pub enum PropValue {
32    /// String property.
33    Str(String),
34    /// 64-bit float property.
35    F64(f64),
36    /// 64-bit signed integer property.
37    I64(i64),
38    /// 64-bit unsigned integer property.
39    U64(u64),
40    /// Boolean property.
41    Bool(bool),
42}
43
44/// A processed feature ready for tile encoding.
45///
46/// Coordinates are in tile-local space [0, `TILE_EXTENT`] after projection
47/// and clipping. Properties are key-value pairs that become MVT tags.
48///
49/// Properties use `Arc` for copy-on-write sharing — all tile features
50/// derived from the same source feature share one allocation until
51/// mutation (e.g. height quantization) triggers a clone.
52#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
53pub struct TileFeature {
54    /// Which output layer this feature belongs to.
55    pub layer: Layer,
56    /// Optional feature ID (from Overture or generated).
57    pub id: u64,
58    /// Geometry type.
59    pub geom_type: GeomType,
60    /// Encoded geometry commands in MVT format (pre-encoded).
61    ///
62    /// This is the raw `repeated uint32 geometry` from the MVT spec.
63    /// Pre-encoding avoids a second pass during tile assembly.
64    pub geometry: Vec<u32>,
65    /// Feature properties as key-value pairs (Arc-shared for COW).
66    pub properties: Arc<Vec<(String, PropValue)>>,
67    /// Sort key for ordering within a layer (lower = drawn first / underneath).
68    pub sort_key: i32,
69}