Skip to content

Commit

Permalink
remove stac-pydantic
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Jul 19, 2023
1 parent c5707d1 commit e6b6336
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 60 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* replace variable `TileMatrixSetId` by `tileMatrixSetId`
* add `pixel_selection_dependency` attribute to the `MosaicTilerFactory`
* re-order endpoints in `MosaicTilerFactory` to avoid conflicts between `tiles` and `assets` endpoints
* remove deprecater `/{searchid}/{z}/{x}/{y}/assets` endpoints
* remove deprecated `/{searchid}/{z}/{x}/{y}/assets` endpoints
* remove `stac-pydantic` dependency
* replace Enum's with `Literal` types

## 0.4.1 (2023-06-21)

Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ classifiers = [
dependencies = [
"titiler.core>=0.12.0,<0.13",
"titiler.mosaic>=0.12.0,<0.13",
"geojson-pydantic",
"stac-pydantic==2.0.*",
"geojson-pydantic~=0.6",
"pydantic~=1.0",
]
dynamic = ["version"]
Expand Down
69 changes: 12 additions & 57 deletions titiler/pgstac/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,28 @@
Note: This is mostly a copy of https://github.com/stac-utils/stac-fastapi/blob/master/stac_fastapi/pgstac/stac_fastapi/pgstac/types/search.py
"""

import operator
from datetime import datetime
from enum import Enum, auto
from types import DynamicClassAttribute
from typing import Any, Callable, Dict, List, Optional, Union

from geojson_pydantic.geometries import (
LineString,
MultiLineString,
MultiPoint,
MultiPolygon,
Point,
Polygon,
)
from typing import Any, Dict, List, Literal, Optional

from geojson_pydantic.geometries import Geometry
from geojson_pydantic.types import BBox
from pydantic import BaseModel, Field, root_validator, validator
from stac_pydantic.shared import BBox
from stac_pydantic.utils import AutoValueEnum

from titiler.core.resources.enums import MediaType

# TODO: add "startsWith", "endsWith", "contains", "in"
Operator = Literal["eq", "ne", "lt", "lte", "gt", "gte"]

class FilterLang(str, Enum):
"""filter language.
ref: https://github.com/radiantearth/stac-api-spec/tree/master/fragments/filter#get-query-parameters-and-post-json-fields
"""

cql_json = "cql-json"
cql_text = "cql-text"
cql2_json = "cql2-json"


class Operator(str, AutoValueEnum):
"""Defines the set of operators supported by the API."""
# ref: https://github.com/radiantearth/stac-api-spec/tree/master/fragments/filter#get-query-parameters-and-post-json-fields
FilterLang = Literal["cql-json", "cql-text", "cql2-json"]

eq = auto()
ne = auto()
lt = auto()
lte = auto()
gt = auto()
gte = auto()
# TODO: These are defined in the spec but aren't currently implemented by the api
# startsWith = auto()
# endsWith = auto()
# contains = auto()
# in = auto()

@DynamicClassAttribute
def operator(self) -> Callable[[Any, Any], bool]:
"""Return python operator."""
return getattr(operator, self._value_)


class SearchType(str, Enum):
"""Search type."""

mosaic = "mosaic"
search = "search"
SearchType = Literal["mosaic", "search"]


class Metadata(BaseModel):
"""Metadata Model."""

type: SearchType = SearchType.mosaic
type: SearchType = "mosaic"

# WGS84 bounds
bounds: Optional[BBox]
Expand Down Expand Up @@ -100,7 +58,6 @@ class Metadata(BaseModel):
class Config:
"""Config for model."""

use_enum_values = True
extra = "allow"


Expand All @@ -115,9 +72,7 @@ class PgSTACSearch(BaseModel):
collections: Optional[List[str]] = None
ids: Optional[List[str]] = None
bbox: Optional[BBox]
intersects: Optional[
Union[Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon]
]
intersects: Optional[Geometry]
query: Optional[Dict[str, Dict[Operator, Any]]]
filter: Optional[Dict]
datetime: Optional[str] = None
Expand Down Expand Up @@ -202,7 +157,7 @@ class Search(BaseModel):
def validate_metadata(cls, v):
"""Set SearchType.search when not present in metadata."""
if "type" not in v:
v["type"] = SearchType.search.name
v["type"] = "search"

return v

Expand Down

0 comments on commit e6b6336

Please sign in to comment.