-
Notifications
You must be signed in to change notification settings - Fork 28
/
types.py
172 lines (131 loc) · 4.54 KB
/
types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
from __future__ import annotations
import os
from typing import (
Dict,
Iterable,
List,
Literal,
Optional,
Protocol,
Tuple,
TypedDict,
Union,
runtime_checkable,
)
from mapchete._deprecated import deprecated
from fiona.crs import CRS as FionaCRS # type: ignore
from geojson_pydantic import Feature, FeatureCollection as GeoJSONGeometryType
from pydantic import BaseModel
from rasterio.crs import CRS as RasterioCRS
from rasterio.enums import Resampling
from shapely.geometry import (
GeometryCollection,
LinearRing,
LineString,
MultiLineString,
MultiPoint,
MultiPolygon,
Point,
Polygon,
)
from shapely.geometry.base import BaseGeometry
from tilematrix import Shape, Tile
SinglepartGeometry = Union[
Point,
LineString,
LinearRing,
Polygon,
]
MultipartGeometry = Union[
MultiPoint,
MultiLineString,
MultiPolygon,
GeometryCollection,
]
Geometry = Union[SinglepartGeometry, MultipartGeometry, BaseGeometry]
@runtime_checkable
class GeoInterface(Protocol):
__geo_interface__: Union[
GeoJSONGeometryType, Dict[Literal["geometry"], GeoJSONGeometryType]
]
GeometryLike = Union[Geometry, GeoJSONGeometryType, GeoInterface, Feature, Dict]
CoordArrays = Tuple[Iterable[float], Iterable[float]]
GeoJSONLikeFeature = TypedDict(
"GeoJSONLikeFeature", {"geometry": dict, "properties": dict}
)
MPathLike = Union[str, os.PathLike]
BoundsLike = Union[List[float], Tuple[float, float, float, float], dict, Polygon]
ShapeLike = Union[Shape, List[int], Tuple[int, int]]
ZoomLevelsLike = Union[List[int], int, dict]
TileLike = Union[Tile, Tuple[int, int, int]]
CRSLike = Union[FionaCRS, RasterioCRS]
NodataVal = Optional[float]
NodataVals = Union[List[NodataVal], NodataVal]
ResamplingLike = Union[Resampling, str]
BandIndex = int
BandIndexes = Union[BandIndex, List[BandIndex]]
def to_resampling(resampling: ResamplingLike) -> Resampling:
if isinstance(resampling, Resampling):
return resampling
return Resampling[resampling]
class Progress(BaseModel):
current: int = 0
total: Optional[int] = None
# below are deprecated classes once sitting in this module:
@deprecated("mapchete.types.Bounds has been moved to mapchete.bounds.Bounds")
class Bounds: # pragma: no cover
def __new__(cls, *args, **kwargs):
from mapchete.bounds import Bounds
# Redirect instantiation to the new class
return Bounds(*args, **kwargs)
@staticmethod
def from_inp(
inp: BoundsLike, strict: bool = True, crs: Optional[CRSLike] = None
): # pragma: no cover
from mapchete.bounds import Bounds
return Bounds.from_inp(inp=inp, strict=strict, crs=crs)
@staticmethod
def from_dict(
inp: dict, strict: bool = True, crs: Optional[CRSLike] = None
): # pragma: no cover
return Bounds(**inp, strict=strict, crs=crs)
@deprecated("mapchete.types.Grid has been moved to mapchete.grid.Grid")
class Grid: # pragma: no cover
def __new__(cls, *args, **kwargs):
from mapchete.grid import Grid
return Grid(*args, **kwargs)
@staticmethod
def from_obj(obj): # pragma: no cover
from mapchete.grid import Grid
return Grid.from_obj(obj)
@staticmethod
def from_bounds(
bounds: BoundsLike, shape: ShapeLike, crs: CRSLike
): # pragma: no cover
from mapchete.grid import Grid
return Grid.from_bounds(bounds=bounds, shape=shape, crs=crs)
@deprecated(
"mapchete.types.ZoomLevels has been moved to mapchete.zoom_levels.ZoomLevels"
)
class ZoomLevels: # pragma: no cover
def __new__(cls, *args, **kwargs): # pragma: no cover
from mapchete.zoom_levels import ZoomLevels
return ZoomLevels(*args, **kwargs)
@staticmethod
def from_inp(
min: ZoomLevelsLike, max: Optional[int] = None, descending: bool = False
): # pragma: no cover
from mapchete.zoom_levels import ZoomLevels
return ZoomLevels.from_inp(min=min, max=max, descending=descending)
@staticmethod
def from_int(inp: int, **kwargs): # pragma: no cover
from mapchete.zoom_levels import ZoomLevels
return ZoomLevels.from_int(inp=inp, **kwargs)
@staticmethod
def from_list(inp: List[int], **kwargs): # pragma: no cover
from mapchete.zoom_levels import ZoomLevels
return ZoomLevels.from_list(inp=inp, **kwargs)
@staticmethod
def from_dict(inp: dict, **kwargs): # pragma: no cover
from mapchete.zoom_levels import ZoomLevels
return ZoomLevels.from_dict(inp=inp, **kwargs)