utiles_core/geostats.rs
1//! Geostats structs/models/objs
2//!
3//! ref: [mapbox/mapbox-geostats](https://github.com/mapbox/mapbox-geostats)
4//!
5//! Usually comes from tippecanoe's `json` metadata field from a mbtiles db.
6//!
7//! Converted w/ the help of chadwick-general-purpose-tool (`ChadGPT`) from geostats schema.
8use serde::{Deserialize, Serialize};
9
10/// `TileStats` struct
11#[derive(Debug, Serialize, Deserialize)]
12#[serde(rename_all = "camelCase")]
13pub struct TileStats {
14 /// Layer count
15 pub layer_count: f64,
16
17 /// Layers
18 pub layers: Vec<Layer>,
19}
20
21/// Layer struct
22#[derive(Debug, Serialize, Deserialize)]
23#[serde(rename_all = "camelCase")]
24pub struct Layer {
25 /// Layer name
26 pub layer: String,
27 /// Feature count
28 pub count: f64,
29 /// Geometry type
30 pub geometry: GeometryType,
31 /// Attribute count
32 pub attribute_count: f64,
33 /// Attributes
34 pub attributes: Vec<Attribute>,
35}
36
37/// `GeometryType` enum
38#[derive(Debug, Serialize, Deserialize)]
39pub enum GeometryType {
40 /// Point
41 Point,
42 /// `LineString`
43 LineString,
44 /// Polygon
45 Polygon,
46}
47
48/// Attribute struct
49#[derive(Debug, Serialize, Deserialize)]
50pub struct Attribute {
51 /// Attribute name
52 pub attribute: String,
53 /// Value count
54 pub count: f64,
55 /// Data type
56 pub r#type: DataType,
57 /// Values
58 pub values: Vec<serde_json::Value>,
59 /// Min value
60 pub min: Option<f64>,
61 /// Max value
62 pub max: Option<f64>,
63}
64
65/// Attribute `DataType` enum
66#[derive(Debug, Serialize, Deserialize)]
67#[serde(rename_all = "lowercase")]
68pub enum DataType {
69 /// String data type
70 String,
71 /// Number data type
72 Number,
73 /// Boolean data type
74 Boolean,
75 /// Null data type
76 Null,
77 /// Mixed data type
78 Mixed,
79}