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.

Axis

Bases: BaseModel

An axis of a coordinate system

Parameters:

Name Type Description Default
name StrictStr

The name of the axis

required
type Optional[AxisType]

The type of the axis

required
unit Optional[Unit]

The unit of the axis

required
description Optional[str]

A description of the axis

required
Source code in src/microjson/model.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class Axis(BaseModel):
    """An axis of a coordinate system

    Args:
        name (StrictStr): The name of the axis
        type (Optional[AxisType]): The type of the axis
        unit (Optional[Unit]): The unit of the axis
        description (Optional[str]): A description of the axis
    """

    name: StrictStr
    type: Optional[AxisType] = None
    unit: Optional[Unit] = None
    description: Optional[str] = None

AxisType

Bases: Enum

The type of an axis

Source code in src/microjson/model.py
68
69
70
71
72
73
class AxisType(Enum):
    """The type of an axis"""

    SPACE = "space"
    TIME = "time"
    CHANNEL = "channel"

CoordinateTransformation

Bases: BaseModel

Coordinate transformation abstract class harmonized with the OME model

Source code in src/microjson/model.py
92
93
94
class CoordinateTransformation(BaseModel):
    """Coordinate transformation abstract class
    harmonized with the OME model"""

GeoJSON

Bases: RootModel

The root object of a GeoJSON file

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

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

Identity

Bases: CoordinateTransformation

Identity transformation for coordinates

Parameters:

Name Type Description Default
type Literal['identity']

The type of the transformation

required
Source code in src/microjson/model.py
 97
 98
 99
100
101
102
103
104
class Identity(CoordinateTransformation):
    """Identity transformation for coordinates

    Args:
        type (Literal["identity"]): The type of the transformation
    """

    type: Literal["identity"] = "identity"

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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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    
    """

    multiscale: Optional[Multiscale] = None
    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 collection

required
provenance Optional[Union[Workflow, WorkflowCollection, Artifact, ArtifactCollection]]

The provenance of the feature collection

required
Source code in src/microjson/model.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
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 collection
        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
185
186
187
188
189
190
class MicroJSON(RootModel):
    """The root object of a MicroJSON file"""

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

Multiscale

Bases: BaseModel

A coordinate system for MicroJSON coordinates

Parameters:

Name Type Description Default
axes List[Axis]

The axes of the coordinate system

required
coordinateTransformations Optional[List[CoordinateTransformation]]

A list of coordinate transformations

required
transformationMatrix Optional[List[List[float]]

The transformation matrix

required
Source code in src/microjson/model.py
131
132
133
134
135
136
137
138
139
140
141
142
class Multiscale(BaseModel):
    """A coordinate system for MicroJSON coordinates

    Args:
        axes (List[Axis]): The axes of the coordinate system
        coordinateTransformations (Optional[List[CoordinateTransformation]]): A list of coordinate transformations
        transformationMatrix (Optional[List[List[float]]): The transformation matrix
    """

    axes: List[Axis]
    coordinateTransformations: Optional[List[CoordinateTransformation]] = None
    transformationMatrix: Optional[List[List[float]]] = None

Scale

Bases: CoordinateTransformation

Scale transformation

Parameters:

Name Type Description Default
type Literal['scale']

The type of the transformation

required
scale List[float]

The scale vector

required
Source code in src/microjson/model.py
119
120
121
122
123
124
125
126
127
128
class Scale(CoordinateTransformation):
    """Scale transformation

    Args:
        type (Literal["scale"]): The type of the transformation
        scale (List[float]): The scale vector
    """

    type: Literal["scale"] = "scale"
    scale: List[float]

Translation

Bases: CoordinateTransformation

Translation transformation

Parameters:

Name Type Description Default
type Literal['translation']

The type of the transformation

required
translation List[float]

The translation vector

required
Source code in src/microjson/model.py
107
108
109
110
111
112
113
114
115
116
class Translation(CoordinateTransformation):
    """Translation transformation

    Args:
        type (Literal["translation"]): The type of the transformation
        translation (List[float]): The translation vector
    """

    type: Literal["translation"] = "translation"
    translation: List[float]

Unit

Bases: Enum

A unit of measurement

Source code in src/microjson/model.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Unit(Enum):
    """A unit of measurement"""

    ANGSTROM = "angstrom"
    ATTOMETER = "attometer"
    CENTIMETER = "centimeter"
    DECIMETER = "decimeter"
    EXAMETER = "exameter"
    FEMTOMETER = "femtometer"
    FOOT = "foot"
    GIGAMETER = "gigameter"
    HECTOMETER = "hectometer"
    INCH = "inch"
    KILOMETER = "kilometer"
    MEGAMETER = "megameter"
    METER = "meter"
    MICROMETER = "micrometer"
    MILE = "mile"
    MILLIMETER = "millimeter"
    NANOMETER = "nanometer"
    PARSEC = "parsec"
    PETAMETER = "petameter"
    PICOMETER = "picometer"
    TERAMETER = "terameter"
    YARD = "yard"
    YOCTOMETER = "yoctometer"
    YOTTAMETER = "yottameter"
    ZEPTOMETER = "zeptometer"
    ZETTAMETER = "zettameter"
    PIXEL = "pixel"
    RADIAN = "radian"
    DEGREE = "degree"

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

Multiscale

A coordinate system for MicroJSON features or feature collections.

Bases: BaseModel

A coordinate system for MicroJSON coordinates

Parameters:

Name Type Description Default
axes List[Axis]

The axes of the coordinate system

required
coordinateTransformations Optional[List[CoordinateTransformation]]

A list of coordinate transformations

required
transformationMatrix Optional[List[List[float]]

The transformation matrix

required
Source code in src/microjson/model.py
131
132
133
134
135
136
137
138
139
140
141
142
class Multiscale(BaseModel):
    """A coordinate system for MicroJSON coordinates

    Args:
        axes (List[Axis]): The axes of the coordinate system
        coordinateTransformations (Optional[List[CoordinateTransformation]]): A list of coordinate transformations
        transformationMatrix (Optional[List[List[float]]): The transformation matrix
    """

    axes: List[Axis]
    coordinateTransformations: Optional[List[CoordinateTransformation]] = None
    transformationMatrix: Optional[List[List[float]]] = None

GeometryCollection

A coordinate system for MicroJSON features or feature collections.

Bases: BaseModel

A coordinate system for MicroJSON coordinates

Parameters:

Name Type Description Default
axes List[Axis]

The axes of the coordinate system

required
coordinateTransformations Optional[List[CoordinateTransformation]]

A list of coordinate transformations

required
transformationMatrix Optional[List[List[float]]

The transformation matrix

required
Source code in src/microjson/model.py
131
132
133
134
135
136
137
138
139
140
141
142
class Multiscale(BaseModel):
    """A coordinate system for MicroJSON coordinates

    Args:
        axes (List[Axis]): The axes of the coordinate system
        coordinateTransformations (Optional[List[CoordinateTransformation]]): A list of coordinate transformations
        transformationMatrix (Optional[List[List[float]]): The transformation matrix
    """

    axes: List[Axis]
    coordinateTransformations: Optional[List[CoordinateTransformation]] = None
    transformationMatrix: Optional[List[List[float]]] = None

GeometryCollection

A collection of multiple geometries. From geojson-pydantic(https://developmentseed.org/geojson-pydantic/), included here for reference.

Feature

Represents a GeoJSON feature object, from geojson-pydantic(https://developmentseed.org/geojson-pydantic/), included here for reference.

FeatureCollection

Represents a GeoJSON feature collection, from geojson-pydantic(https://developmentseed.org/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
28
29
30
31
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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    
    """

    multiscale: Optional[Multiscale] = None
    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 collection

required
provenance Optional[Union[Workflow, WorkflowCollection, Artifact, ArtifactCollection]]

The provenance of the feature collection

required
Source code in src/microjson/model.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
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 collection
        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
185
186
187
188
189
190
class MicroJSON(RootModel):
    """The root object of a MicroJSON file"""

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