GeoJSON¶
GeoJSON (RFC 7946)
FeatureandFeatureCollectionmodels with gazebo's hypermedia links, for OGC API Features item endpoints.
Optional extra
The GeoJSON models live behind the gazebo[geojson] extra — install it to
import gazebo.geojson. They build on
geojson-pydantic for
coordinate-validated geometry (the seven GeoJSON geometry types are
re-exported), so the core dependency footprint stays pydantic-only.
The item payloads of an OGC Features collection are GeoJSON. gazebo.geojson
reuses geojson-pydantic for the geometry/feature shapes — the tedious,
easy-to-get-subtly-wrong coordinate validation — and layers gazebo's deferred
links on top:
Feature[P]is generic over itspropertiesmodelP, inherits geometry validation, and adds alinksarray.FeatureCollection[P]is aLinkedCollection, so it carrieslinks,numberReturned/numberMatched, and an optional top-levelbbox— none of which geojson-pydantic's own collection has. Items serialize under the GeoJSONfeatureskey.
from pydantic import BaseModel
from gazebo.geojson import Feature, FeatureCollection, Point, Position2D
from gazebo.link import Link
from gazebo.rels import MediaType, Rel
class BedProperties(BaseModel):
name: str
# `Feature` is generic over its `properties` model; geometry is coordinate-validated
# by geojson-pydantic, and gazebo adds the deferred `links`.
rose_bed = Feature[BedProperties](
id='roses',
geometry=Point(type='Point', coordinates=Position2D(-122.6, 45.5)),
properties=BedProperties(name='Rose Bed'),
links=[Link.self_link(type=MediaType.GEOJSON)],
)
# `FeatureCollection` is a LinkedCollection: items serialize under `features`, and
# it carries `links` + `numberReturned` (and an optional top-level `bbox`).
beds = FeatureCollection[BedProperties](
items=[rose_bed],
links=[Link.root_link(rel=Rel.ROOT)],
)
Because FeatureCollection is a LinkedCollection, the same deferred-link
machinery applies: build it in business logic with no request in hand, and the
hrefs resolve at serialization. Pair it with the
query-parameter adapters for bbox/datetime/crs filtering and the
Collection/Extent metadata models to stand up a
full OGC Features collection — see the garden example.
Reference¶
See gazebo.geojson.