Skip to content

Commit

Permalink
Geojson pydantic (#12)
Browse files Browse the repository at this point in the history
* Added packages

* cleaned up example

* Commit test

* Added pre-commit hooks

* Formatting

* Updated example

* Update package

* Added multilevel metadata test

* Bump version 0.1.8 -> 0.1.9

* Added mkdocstrings pip

* Added trigger

* Added handler

* Added provenance

* Added provenance

* Added provenance

* Added provenance

* Added documentation and tests for provenance

* Corrected string

* Added TileJSON for MicroJSON

* Added examples for tiling and description

* Removed garbage files

* Restructured tile examples

* Updated TileJSON fields, added relative file URL

* Bump version 0.1.9 -> 0.1.10

* Initial roadmap

* Updated naming and documentation

* Harmonized with OME NGFF multiscale

* Reverted indexing in utils.py

* Added hierarchies

* Bump version 0.1.10 -> 0.1.11

* Updated packages

* Corrected roadmap markdown

* Added module examples

* Moved module examples

* Corrected model reference

* Revised roadmap

* Replaced GeoJSON objects to geojson-pydantic

* Altered documentation after replacing GeoJSON

---------

Co-authored-by: Nicholas-Schaub <[email protected]>
  • Loading branch information
bengtl and Nicholas-Schaub authored May 13, 2024
1 parent 3a94175 commit 1c0bc8f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 107 deletions.
35 changes: 11 additions & 24 deletions docs/pydantic.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
87 changes: 4 additions & 83 deletions src/microjson/model.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -82,33 +23,13 @@ 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"""

min: float
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"""

Expand Down

0 comments on commit 1c0bc8f

Please sign in to comment.