|
1 | 1 | # Overture Schema Core |
2 | 2 |
|
3 | | -Core Pydantic models and base classes for Overture Maps schemas, providing foundational types, geometry handling, and a comprehensive scoping system for conditional rule application. |
| 3 | +Shared models and conventions for building Overture Maps feature types. Defines the base feature class all themes extend, a scoping framework for expressing conditional values (this speed limit applies *here*, *then*, to *these vehicles*), and common structures for names, sources, and cartographic hints. |
4 | 4 |
|
5 | 5 | ## Installation |
6 | 6 |
|
7 | 7 | ```bash |
8 | 8 | pip install overture-schema-core |
9 | 9 | ``` |
10 | 10 |
|
11 | | -## Key Components |
| 11 | +## OvertureFeature |
12 | 12 |
|
13 | | -- **Base Classes**: Extensible base models for Overture Maps features |
14 | | -- **Geometry Types**: WKB geometry type hints and utilities |
15 | | -- **Common Structures**: Shared models used across all themes |
16 | | -- **Primitive Data Types**: Validated primitive types with multi-target serialization support |
17 | | -- **Scoping System**: Flexible conditional rule application framework |
18 | | - |
19 | | -## Enhanced Primitive Types |
20 | | - |
21 | | -The enhanced primitive types system provides validated primitive types with automatic |
22 | | -constraint checking and multi-target serialization support. This enables consistent type |
23 | | -definitions that can generate appropriate representations for different targets (Spark, |
24 | | -Parquet, etc.). |
25 | | - |
26 | | -### Available Types |
27 | | - |
28 | | -Built-in Python primitive types (`str`, `int`, `float`, `bool`, `list`, etc.) are |
29 | | -automatically mapped. |
30 | | - |
31 | | -We also provide the following additional types: |
32 | | - |
33 | | -#### Integer Types |
34 | | - |
35 | | -- **`uint8`**: 8-bit unsigned integer (0-255) |
36 | | -- **`uint16`**: 16-bit unsigned integer (0-65535) |
37 | | -- **`uint32`**: 32-bit unsigned integer (0-4294967295) |
38 | | -- **`int8`**: 8-bit signed integer (-128 to 127) |
39 | | -- **`int32`**: 32-bit signed integer (-2³¹ to 2³¹-1) |
40 | | -- **`int64`**: 64-bit signed integer (-2⁶³ to 2⁶³-1) |
41 | | - |
42 | | -#### Floating Point Types |
43 | | - |
44 | | -- **`float32`**: 32-bit floating point number |
45 | | -- **`float64`**: 64-bit floating point number |
46 | | - |
47 | | -### Basic Usage |
| 13 | +Every Overture feature type inherits from `OvertureFeature`, which extends `system.Feature` with the fields present on all Overture data: `id`, `theme`, `type`, `version`, `geometry`, and `sources`. |
48 | 14 |
|
49 | 15 | ```python |
50 | | -from pydantic import BaseModel, Field |
51 | | -from overture.schema.core.primitives import ( |
52 | | - uint8, uint32, float32 |
53 | | -) |
54 | | - |
55 | | -class Building(BaseModel): |
56 | | - """Building feature with specific primitive data types.""" |
57 | | - |
58 | | - height: float32 | None = Field( |
59 | | - None, |
60 | | - description="Height of building in meters" |
61 | | - ) |
62 | | - |
63 | | - num_floors: uint8 | None = Field( |
64 | | - None, |
65 | | - description="Number of floors in building" |
66 | | - ) |
67 | | - |
68 | | - area: uint32 | None = Field( |
69 | | - None, |
70 | | - description="Floor area in square meters" |
71 | | - ) |
| 16 | +from typing import Literal |
| 17 | +from overture.schema.core import OvertureFeature |
| 18 | + |
| 19 | +class Park(OvertureFeature[Literal["places"], Literal["park"]]): |
| 20 | + area_hectares: float | None = None |
72 | 21 | ``` |
73 | 22 |
|
74 | | -### Automatic Validation |
| 23 | +## Scoping |
75 | 24 |
|
76 | | -Enhanced primitive types automatically validate constraints: |
| 25 | +Many Overture values only apply under specific conditions -- a speed limit that holds during rush hour, along a sub-segment, in the forward direction. The `@scoped` decorator adds conditional fields to any Pydantic model: |
77 | 26 |
|
78 | 27 | ```python |
79 | | -# Valid values |
80 | | -building = Building(height=45.5, num_floors=12, area=2500) |
| 28 | +from pydantic import BaseModel |
| 29 | +from overture.schema.core.scoping import Scope, scoped |
| 30 | +from overture.schema.system.primitive import float32 |
81 | 31 |
|
82 | | -# Invalid values raise ValidationError |
83 | | -Building(num_floors=256) # Error: 256 > UInt8 maximum (255) |
84 | | -Building(num_floors=-1) # Error: -1 < UInt8 minimum (0) |
| 32 | +@scoped(Scope.GEOMETRIC_RANGE, Scope.TEMPORAL) |
| 33 | +class SpeedLimit(BaseModel): |
| 34 | + max_speed: float32 |
85 | 35 | ``` |
86 | 36 |
|
87 | | -### Type Safety |
| 37 | +This produces a model with `between` (geometric range) and `when.during` (temporal) fields, both optional. The full set of scopes and the fields they inject: |
88 | 38 |
|
89 | | -The enhanced primitive types provide strong type safety guarantees at both static and |
90 | | -runtime levels: |
| 39 | +| Scope | Field | |
| 40 | +|----------------------------|-------------------| |
| 41 | +| `Scope.GEOMETRIC_POSITION` | `at` | |
| 42 | +| `Scope.GEOMETRIC_RANGE` | `between` | |
| 43 | +| `Scope.HEADING` | `when.heading` | |
| 44 | +| `Scope.TEMPORAL` | `when.during` | |
| 45 | +| `Scope.TRAVEL_MODE` | `when.mode` | |
| 46 | +| `Scope.PURPOSE_OF_USE` | `when.using` | |
| 47 | +| `Scope.RECOGNIZED_STATUS` | `when.recognized` | |
| 48 | +| `Scope.SIDE` | `side` | |
| 49 | +| `Scope.VEHICLE` | `when.vehicle` | |
91 | 50 |
|
92 | | -**Static Type Checking**: mypy can distinguish between different primitive types, |
93 | | -*preventing common errors: |
| 51 | +Scopes are optional by default. Make them mandatory via `required`: |
94 | 52 |
|
95 | 53 | ```python |
96 | | -from overture.schema.core.primitives import uint8, uint32 |
| 54 | +@scoped(Scope.TEMPORAL, required=(Scope.GEOMETRIC_POSITION, Scope.HEADING)) |
| 55 | +class TrafficSignal(BaseModel): |
| 56 | + signal_type: str |
| 57 | +``` |
97 | 58 |
|
98 | | -def process_floor_count(floors: uint8) -> str: |
99 | | - return f"Building has {floors} floors" |
| 59 | +## Names |
100 | 60 |
|
101 | | -def process_area(area: uint32) -> str: |
102 | | - return f"Area: {area} sq meters" |
| 61 | +Multilingual naming with support for common names, name rules (official, alternate, short variants), and scoping by geometric range, side, or political perspective. Mix `Named` into a feature type to give it a `names` field: |
103 | 62 |
|
104 | | -# Type checker prevents mixing incompatible types |
105 | | -floors: uint8 = 12 |
106 | | -area: uint32 = 2500 |
| 63 | +```python |
| 64 | +from typing import Literal |
| 65 | +from overture.schema.core import OvertureFeature |
| 66 | +from overture.schema.core.names import Named |
107 | 67 |
|
108 | | -process_floor_count(area) # mypy error: Expected UInt8, got UInt32 |
109 | | -process_area(floors) # mypy error: Expected UInt32, got UInt8 |
| 68 | +class Lake(OvertureFeature[Literal["base"], Literal["water"]], Named): |
| 69 | + pass # inherits names: Names | None from Named |
110 | 70 | ``` |
111 | 71 |
|
| 72 | +Name rules support geometric range and side scoping for cases like a street whose name changes partway along or differs on each side. `NameRule` variants: `common`, `official`, `alternate`, `short`. |
112 | 73 |
|
113 | | -### Examples |
| 74 | +## Sources |
114 | 75 |
|
115 | | -#### Temporal Speed Limit |
116 | | - |
117 | | -```yaml |
118 | | -speed_limits: |
119 | | - - between: [0, 1] |
120 | | - max_speed: {value: 30, unit: km/h} |
121 | | - when: |
122 | | - during: "Mo-Fr 07:00-09:00,17:00-19:00" # Rush hours only |
123 | | -``` |
| 76 | +Source attribution tracking. Each `SourceItem` identifies which dataset a feature or property came from, with optional license, record ID, update time, and confidence score. Source items support geometric range scoping for per-segment attribution. |
124 | 77 |
|
125 | | -#### Vehicle-Specific Access Restriction |
126 | | -
|
127 | | -```yaml |
128 | | -access_restrictions: |
129 | | - - between: [0.2, 0.8] |
130 | | - access_type: denied |
131 | | - when: |
132 | | - vehicle: |
133 | | - - dimension: weight |
134 | | - comparison: greater_than |
135 | | - value: 7.5 |
136 | | - unit: t |
137 | | -``` |
138 | | -
|
139 | | -#### Multi-Dimensional Scoping |
140 | | -
|
141 | | -```yaml |
142 | | -access_restrictions: |
143 | | - - between: [0, 1] |
144 | | - access_type: denied |
145 | | - when: |
146 | | - mode: [bus] |
147 | | - during: "Mo-Fr 15:00-18:00" |
148 | | - heading: forward |
149 | | - using: [to_deliver] |
| 78 | +```python |
| 79 | +from overture.schema.core.sources import SourceItem |
| 80 | + |
| 81 | +sources = [ |
| 82 | + SourceItem(property="", dataset="OpenStreetMap"), |
| 83 | + SourceItem(property="/geometry", dataset="Microsoft ML Buildings"), |
| 84 | + # first 30% of the segment's geometry came from a different source |
| 85 | + SourceItem(property="/geometry", dataset="County GIS", between=[0, 0.3]), |
| 86 | +] |
150 | 87 | ``` |
151 | 88 |
|
152 | | -### Design Principles |
153 | | -
|
154 | | -1. **Composability**: Mix-in design allows combining only needed scoping dimensions |
155 | | -2. **Reusability**: Base scope classes work across all rule types and themes |
156 | | -3. **Extensibility**: Easy to add new scoping dimensions or modify existing ones |
157 | | -4. **Type Safety**: Full Pydantic validation for all scoping conditions |
158 | | -5. **Linear Reference Integration**: Seamless integration with geometric positioning |
| 89 | +## Cartography |
159 | 90 |
|
160 | | -### Rule Complexity Patterns |
| 91 | +Rendering hints for map-making: `prominence` (1--100 significance scale), `min_zoom`/`max_zoom` (tile zoom bounds), and `sort_key` (draw order). Mix `CartographicallyHinted` into a model to add a `cartography` field. |
161 | 92 |
|
162 | | -- **Simple Rules** (flags, dimensions): Geometric scoping only |
163 | | -- **Complex Rules** (speed limits, access): Geometric + conditional scoping |
164 | | -- **Transition Rules**: Full scoping including directional constraints |
| 93 | +## Also Included |
165 | 94 |
|
166 | | -This scoping system provides the foundation for precise, flexible rule specification across all Overture Maps transportation features. |
| 95 | +- **Types** -- domain-specific aliases built on system primitives: `ConfidenceScore` (0.0--1.0), `Level` (z-order), `FeatureVersion`. |
| 96 | +- **Units** -- measurement enumerations: `SpeedUnit`, `LengthUnit`, `WeightUnit`. |
| 97 | +- **Discovery** -- entry-point-based model registry. Theme packages register models via `overture.models` entry points; `discover_models()` resolves them at runtime. |
0 commit comments