1
1
import abc
2
2
import math
3
- from typing import List , NamedTuple , Optional , Union
3
+ from typing import Dict , List , NamedTuple , Optional , Union
4
4
5
5
import pyproj
6
6
import shapely
@@ -13,7 +13,7 @@ class JobSplittingFailure(Exception):
13
13
14
14
15
15
# TODO: This function is also defined in openeo-python-driver. But maybe we want to avoid a dependency on openeo-python-driver?
16
- def reproject_bounding_box (bbox : dict , from_crs : Optional [str ], to_crs : str ) -> dict :
16
+ def reproject_bounding_box (bbox : Dict , from_crs : Optional [str ], to_crs : str ) -> Dict :
17
17
"""
18
18
Reproject given bounding box dictionary
19
19
@@ -41,15 +41,15 @@ class BoundingBox(NamedTuple):
41
41
crs : str = "EPSG:4326"
42
42
43
43
@classmethod
44
- def from_dict (cls , d : dict ) -> "BoundingBox" :
44
+ def from_dict (cls , d : Dict ) -> "BoundingBox" :
45
45
return cls (** {k : d [k ] for k in cls ._fields if k not in cls ._field_defaults or k in d })
46
46
47
47
@classmethod
48
48
def from_polygon (cls , polygon : shapely .geometry .Polygon , projection : Optional [str ] = None ) -> "BoundingBox" :
49
49
"""Create a bounding box from a shapely Polygon"""
50
50
return cls (* polygon .bounds , projection if projection is not None else cls .crs )
51
51
52
- def as_dict (self ) -> dict :
52
+ def as_dict (self ) -> Dict :
53
53
return self ._asdict ()
54
54
55
55
def as_polygon (self ) -> shapely .geometry .Polygon :
@@ -61,7 +61,7 @@ class TileGridInterface(metaclass=abc.ABCMeta):
61
61
"""Interface for tile grid classes"""
62
62
63
63
@abc .abstractmethod
64
- def get_tiles (self , geometry : Union [dict , shapely .geometry .Polygon ]) -> list [Union [dict , shapely .geometry .Polygon ]]:
64
+ def get_tiles (self , geometry : Union [Dict , shapely .geometry .Polygon ]) -> List [Union [Dict , shapely .geometry .Polygon ]]:
65
65
"""Calculate tiles to cover given bounding box"""
66
66
...
67
67
@@ -80,7 +80,7 @@ def from_size_projection(cls, size: float, projection: str) -> "SizeBasedTileGri
80
80
"""Create a tile grid from size and projection"""
81
81
return cls (projection .lower (), size )
82
82
83
- def get_tiles (self , geometry : Union [dict , shapely .geometry .Polygon ]) -> list [Union [dict , shapely .geometry .Polygon ]]:
83
+ def get_tiles (self , geometry : Union [Dict , shapely .geometry .Polygon ]) -> List [Union [Dict , shapely .geometry .Polygon ]]:
84
84
if isinstance (geometry , dict ):
85
85
bbox = BoundingBox .from_dict (geometry )
86
86
bbox_crs = bbox .crs
@@ -123,8 +123,8 @@ def get_tiles(self, geometry: Union[dict, shapely.geometry.Polygon]) -> list[Uni
123
123
124
124
125
125
def split_area (
126
- aoi : Union [dict , shapely .geometry .Polygon ], projection = "EPSG:326" , tile_size : float = 20.0
127
- ) -> list [Union [dict , shapely .geometry .Polygon ]]:
126
+ aoi : Union [Dict , shapely .geometry .Polygon ], projection = "EPSG:326" , tile_size : float = 20.0
127
+ ) -> List [Union [Dict , shapely .geometry .Polygon ]]:
128
128
"""
129
129
Split area of interest into tiles of given size and projection.
130
130
:param aoi: area of interest (bounding box or shapely polygon)
0 commit comments