Skip to content

Pydantic Models for MicroJSON and GeoJSON

Introduction

This document describes the Pydantic models used for GeoJSON and MicroJSON objects. These models leverage Python's type hinting and Pydantic's validation mechanisms, making it robust and efficient to work with complex GeoJSON and MicroJSON objects.

Models

MicroJSON and GeoJSON models, defined manually using pydantic.

GeoJSON

Bases: RootModel

The root object of a GeoJSON file

Source code in src/microjson/model.py
27
28
29
30
class GeoJSON(RootModel):
    """The root object of a GeoJSON file"""

    root: Union[Feature, FeatureCollection, GeometryType]  # type: ignore

MicroFeature

Bases: Feature

A MicroJSON feature, which is a GeoJSON feature with additional metadata

Parameters:

Name Type Description Default
multiscale Optional[Multiscale]

The coordinate system of the feature

required
ref Optional[Union[StrictStr, StrictInt]]

A reference to the parent feature

required
parentId Optional[Union[StrictStr, StrictInt]]

A reference to the parent feature

required
featureClass Optional[str]

The class of the feature

required
Source code in src/microjson/model.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class MicroFeature(Feature):
    """A MicroJSON feature, which is a GeoJSON feature with additional
    metadata

    Args:
        multiscale (Optional[Multiscale]): The coordinate system of the feature
        ref (Optional[Union[StrictStr, StrictInt]]):
            A reference to the parent feature
        parentId (Optional[Union[StrictStr, StrictInt]]):
            A reference to the parent feature
        featureClass (Optional[str]): The class of the feature
    """

    ref: Optional[Union[StrictStr, StrictInt]] = None
    # reference to the parent feature
    parentId: Optional[Union[StrictStr, StrictInt]] = None
    # for now, only string feature class is supported
    # in the future, it may be expanded with a class registry
    featureClass: Optional[str] = None

MicroFeatureCollection

Bases: FeatureCollection

A MicroJSON feature collection, which is a GeoJSON feature collection with additional metadata.

Parameters:

Name Type Description Default
properties Optional[Props]

The properties of the feature collection

required
id Optional[Union[StrictStr, StrictInt]]

The ID of the feature coll.

required
Source code in src/microjson/model.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class MicroFeatureCollection(FeatureCollection):
    """A MicroJSON feature collection, which is a GeoJSON feature
    collection with additional metadata.

    Args:
        properties (Optional[Props]): The properties of the feature collection
        id (Optional[Union[StrictStr, StrictInt]]): The ID of the feature coll.
        provenance (Optional[Union[Workflow,
            WorkflowCollection,
            Artifact,
            ArtifactCollection]]): The provenance of the feature collection
    """

    properties: Optional[Union[Props, None]] = None  # type: ignore
    id: Optional[Union[StrictStr, StrictInt]] = None
    provenance: Optional[Union[Workflow,
                               WorkflowCollection,
                               Artifact,
                               ArtifactCollection]] = None

MicroJSON

Bases: RootModel

The root object of a MicroJSON file

Source code in src/microjson/model.py
75
76
77
78
79
80
class MicroJSON(RootModel):
    """The root object of a MicroJSON file"""

    root: Union[MicroFeature,  # type: ignore
                MicroFeatureCollection,
                GeometryType]

Base Objects

Geometry Types

Uses geojson-pydantic models for GeoJSON geometry types, included here for reference. Please refer to the geojson-pydantic documentation for more information.

Point

Represents a GeoJSON Point object.

MultiPoint

Represents a GeoJSON MultiPoint object.

LineString

Represents a GeoJSON LineString object.

MultiLineString

Represents a GeoJSON MultiLineString object.

Polygon

Represents a GeoJSON Polygon object.

MultiPolygon

Represents a GeoJSON MultiPolygon object.

Compound Objects

GeometryCollection

A collection of multiple geometries. From geojson-pydantic, included here for reference.

Feature

Represents a GeoJSON feature object, from geojson-pydantic, included here for reference.

FeatureCollection

Represents a GeoJSON feature collection, from geojson-pydantic, included here for reference.

GeoJSON

The root object of a GeoJSON file.

Bases: RootModel

The root object of a GeoJSON file

Source code in src/microjson/model.py
27
28
29
30
class GeoJSON(RootModel):
    """The root object of a GeoJSON file"""

    root: Union[Feature, FeatureCollection, GeometryType]  # type: ignore

MicroJSON Extended Models

MicroFeature

A MicroJSON feature, which is an extension of a GeoJSON feature.

Bases: Feature

A MicroJSON feature, which is a GeoJSON feature with additional metadata

Parameters:

Name Type Description Default
multiscale Optional[Multiscale]

The coordinate system of the feature

required
ref Optional[Union[StrictStr, StrictInt]]

A reference to the parent feature

required
parentId Optional[Union[StrictStr, StrictInt]]

A reference to the parent feature

required
featureClass Optional[str]

The class of the feature

required
Source code in src/microjson/model.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class MicroFeature(Feature):
    """A MicroJSON feature, which is a GeoJSON feature with additional
    metadata

    Args:
        multiscale (Optional[Multiscale]): The coordinate system of the feature
        ref (Optional[Union[StrictStr, StrictInt]]):
            A reference to the parent feature
        parentId (Optional[Union[StrictStr, StrictInt]]):
            A reference to the parent feature
        featureClass (Optional[str]): The class of the feature
    """

    ref: Optional[Union[StrictStr, StrictInt]] = None
    # reference to the parent feature
    parentId: Optional[Union[StrictStr, StrictInt]] = None
    # for now, only string feature class is supported
    # in the future, it may be expanded with a class registry
    featureClass: Optional[str] = None

MicroFeatureCollection

A MicroJSON feature collection, which is an extension of a GeoJSON feature collection.

Bases: FeatureCollection

A MicroJSON feature collection, which is a GeoJSON feature collection with additional metadata.

Parameters:

Name Type Description Default
properties Optional[Props]

The properties of the feature collection

required
id Optional[Union[StrictStr, StrictInt]]

The ID of the feature coll.

required
Source code in src/microjson/model.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class MicroFeatureCollection(FeatureCollection):
    """A MicroJSON feature collection, which is a GeoJSON feature
    collection with additional metadata.

    Args:
        properties (Optional[Props]): The properties of the feature collection
        id (Optional[Union[StrictStr, StrictInt]]): The ID of the feature coll.
        provenance (Optional[Union[Workflow,
            WorkflowCollection,
            Artifact,
            ArtifactCollection]]): The provenance of the feature collection
    """

    properties: Optional[Union[Props, None]] = None  # type: ignore
    id: Optional[Union[StrictStr, StrictInt]] = None
    provenance: Optional[Union[Workflow,
                               WorkflowCollection,
                               Artifact,
                               ArtifactCollection]] = None

MicroJSON

The root object of a MicroJSON file.

Bases: RootModel

The root object of a MicroJSON file

Source code in src/microjson/model.py
75
76
77
78
79
80
class MicroJSON(RootModel):
    """The root object of a MicroJSON file"""

    root: Union[MicroFeature,  # type: ignore
                MicroFeatureCollection,
                GeometryType]