diff --git a/docs/pydantic.md b/docs/pydantic.md index b5474e5..ef97608 100644 --- a/docs/pydantic.md +++ b/docs/pydantic.md @@ -8,11 +8,7 @@ This document describes the Pydantic models used for GeoJSON and MicroJSON objec ::: microjson.model -### Base Models - -#### GeoAbstract - -::: microjson.model.GeoAbstract +### Base Objects #### ValueRange @@ -27,43 +23,34 @@ Metadata properties of a MicroJSON feature. ::: microjson.model.Properties + ### Geometry Types +Uses geojson-pydantic models for GeoJSON geometry types, included here for reference. Please refer to the [geojson-pydantic documentation](https://developmentseed.org/geojson-pydantic/) for more information. #### Point Represents a GeoJSON Point object. -::: microjson.model.Point - #### MultiPoint Represents a GeoJSON MultiPoint object. -::: microjson.model.MultiPoint - #### LineString Represents a GeoJSON LineString object. -::: microjson.model.LineString - #### MultiLineString Represents a GeoJSON MultiLineString object. -::: microjson.model.MultiLineString - #### Polygon Represents a GeoJSON Polygon object. -::: microjson.model.Polygon - #### MultiPolygon Represents a GeoJSON MultiPolygon object. -::: microjson.model.MultiPolygon ### Compound Objects @@ -75,21 +62,21 @@ A coordinate system for MicroJSON features or feature collections. #### GeometryCollection -A collection of multiple geometries. +A coordinate system for MicroJSON features or feature collections. -::: microjson.model.GeometryCollection +::: microjson.model.Multiscale -#### Feature +#### GeometryCollection -Represents a GeoJSON feature object. +A collection of multiple geometries. From geojson-pydantic(https://developmentseed.org/geojson-pydantic/), included here for reference. -::: microjson.model.Feature +#### Feature -#### FeatureCollection +Represents a GeoJSON feature object, from geojson-pydantic(https://developmentseed.org/geojson-pydantic/), included here for reference. -Represents a GeoJSON feature collection. +#### FeatureCollection -::: microjson.model.FeatureCollection +Represents a GeoJSON feature collection, from geojson-pydantic(https://developmentseed.org/geojson-pydantic/), included here for reference. #### GeoJSON diff --git a/pyproject.toml b/pyproject.toml index 55ab50b..032b8c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,7 @@ llvmlite = "^0.40.1" vaex = "^4.17.0" pydantic = "^2.3.0" scikit-image = "0.20.0" +geojson-pydantic = "^1.0.2" [tool.poetry.dev-dependencies] pytest = "^6.2.4" diff --git a/src/microjson/model.py b/src/microjson/model.py index c8bc1b7..fbf5117 100644 --- a/src/microjson/model.py +++ b/src/microjson/model.py @@ -1,73 +1,14 @@ """MicroJSON and GeoJSON models, defined manually using pydantic.""" from typing import List, Optional, Union, Dict, Literal from enum import Enum -from pydantic import BaseModel, Field, StrictInt, StrictStr, conlist, RootModel +from pydantic import BaseModel, StrictInt, StrictStr, RootModel from microjson.provenance import Workflow from microjson.provenance import WorkflowCollection from microjson.provenance import Artifact from microjson.provenance import ArtifactCollection - -Coordinates = conlist(float, min_length=2, max_length=3) - - -class GeoAbstract(BaseModel): - """Abstract base class for all GeoJSON objects""" - - bbox: Optional[List[float]] = Field(None, min_length=4) - - -class Point(GeoAbstract): - """A GeoJSON Point object""" - - type: Literal["Point"] - coordinates: Coordinates # type: ignore - - -class MultiPoint(GeoAbstract): - """A GeoJSON MultiPoint object""" - - type: Literal["MultiPoint"] - coordinates: List[Coordinates] # type: ignore - - -class LineString(GeoAbstract): - """A GeoJSON LineString object""" - - type: Literal["LineString"] - coordinates: List[Coordinates] # type: ignore - - -class MultiLineString(GeoAbstract): - """A GeoJSON MultiLineString object""" - - type: Literal["MultiLineString"] - coordinates: List[List[Coordinates]] # type: ignore - - -class Polygon(GeoAbstract): - """A GeoJSON Polygon object""" - - type: Literal["Polygon"] - coordinates: List[List[Coordinates]] # type: ignore - - -class MultiPolygon(GeoAbstract): - """A GeoJSON MultiPolygon object""" - - type: Literal["MultiPolygon"] - coordinates: List[List[List[Coordinates]]] # type: ignore - - -GeometryBaseType = Union[ - Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon -] - - -class GeometryCollection(GeoAbstract): - """A GeoJSON GeometryCollection object""" - - type: Literal["GeometryCollection"] - geometries: List[GeometryBaseType] +from geojson_pydantic import Feature, FeatureCollection, GeometryCollection +from geojson_pydantic import Point, MultiPoint, LineString, MultiLineString +from geojson_pydantic import Polygon, MultiPolygon GeometryType = Union[ # type: ignore @@ -82,19 +23,6 @@ class GeometryCollection(GeoAbstract): ] -class Feature(GeoAbstract): - """A GeoJSON Feature object""" - - type: Literal["Feature"] - geometry: GeometryType = Field( # type: ignore - ..., - description="""The geometry of the - feature""", - ) # type: ignore - properties: Dict = Field(..., description="""Properties of the feature""") - id: Optional[Union[StrictStr, StrictInt]] = None - - class ValueRange(BaseModel): """A range of values for MicroJSON quantitative properties""" @@ -102,13 +30,6 @@ class ValueRange(BaseModel): max: float -class FeatureCollection(GeoAbstract): - """A GeoJSON FeatureCollection object""" - - type: Literal["FeatureCollection"] - features: List[Feature] - - class GeoJSON(RootModel): """The root object of a GeoJSON file"""