1
1
from enum import Enum
2
- from typing import Optional , List , Any , Dict
2
+ from typing import Optional , List
3
3
4
- from pydantic import BaseModel , validator
4
+ from pydantic import BaseModel , validator , conlist
5
5
import numpy as np
6
- from pyproj import Transformer , transform
6
+ from pyproj import Transformer
7
7
8
8
from ..geometry import Point
9
9
from .base_data import BaseData
@@ -88,15 +88,11 @@ class TiledImageData(BaseData):
88
88
tile_layer : TileLayer
89
89
tile_bounds : TiledBounds
90
90
alternative_layers : List [TileLayer ] = None
91
- zoom_levels : List [ int ]
91
+ zoom_levels : conlist ( item_type = int , min_items = 2 , max_items = 2 )
92
92
max_native_zoom : int = None
93
93
tile_size : Optional [int ]
94
94
version : int = 2
95
95
96
- def __post_init__ (self ):
97
- if self .max_native_zoom is None :
98
- self .max_native_zoom = zoom_levels [1 ]
99
-
100
96
#TODO: look further into Matt's code and how to reference the monorepo ?
101
97
def _as_raster (zoom ):
102
98
# stitched together tiles as a RasterData object
@@ -105,58 +101,45 @@ def _as_raster(zoom):
105
101
image_as_np = None
106
102
return RasterData (arr = image_as_np )
107
103
108
- @property #TODO
104
+ #TODO
105
+ @property
109
106
def value (self ) -> np .ndarray :
110
107
return self ._as_raster (self .min_zoom ).value ()
111
108
112
- #TODO: maybe not necessary, can remove
113
- # @property
114
- # def tile_layer_url(self) -> str:
115
- # return self.tile_layer.url
116
-
117
- #TODO: maybe not necessary, can remove
118
- # @property
119
- # def bounds(self) -> List[Point]:
120
- # return self.tile_bounds.bounds
121
-
122
- #TODO: wondering to keep this or not since epsg may be something of interest
123
- # and they dont want to go through TiledImageData.tile_bounds.epsg?
124
- # then can call TiledimageData.epsg
125
- @property
126
- def epsg (self ) -> EPSG :
127
- return self .tile_bounds .epsg
128
-
129
- @validator ('zoom_levels' )
130
- def validate_zooms (cls , zoom_levels ):
131
- if len (zoom_levels ) != 2 :
132
- raise AssertionError (
133
- f"zoom_levels should contain 2 values [min,max], found { len (zoom_levels )} "
134
- )
135
-
136
109
137
110
#TODO: we will need to update the [data] package to also require pyproj
138
111
class EPSGTransformer (BaseModel ):
139
- """Transformer class between different EPSG's. Useful when wanting to project
112
+ """Transformer class between different EPSG's. Useful when wanting to project
140
113
in different formats.
141
114
142
115
Requires as input a Point object.
143
116
"""
144
- class Config :
145
- arbitrary_types_allowed = True
117
+ class ProjectionTransformer ():
118
+ """Custom class to help represent a Transformer that will play
119
+ nicely with Pydantic.
120
+ """
121
+ @classmethod
122
+ def __get_validators__ (cls ):
123
+ yield cls .validate
124
+
125
+ @classmethod
126
+ def validate (cls , v ):
127
+ return v
146
128
147
- transform_function : Transformer = None
129
+ transform_function : Optional [ ProjectionTransformer ] = None
148
130
149
- def is_simple (self , epsg : EPSG ) -> bool :
131
+ def _is_simple (self , epsg : EPSG ) -> bool :
150
132
return epsg == EPSG .SIMPLEPIXEL
151
133
152
134
def geo_and_geo (self , src_epsg : EPSG , tgt_epsg : EPSG ) -> None :
153
- if self .is_simple (src_epsg ) or self .is_simple (tgt_epsg ):
135
+ if self ._is_simple (src_epsg ) or self ._is_simple (tgt_epsg ):
154
136
raise Exception (
155
137
f"Cannot be used for Simple transformations. Found { src_epsg } and { tgt_epsg } "
156
138
)
157
139
self .transform_function = Transformer .from_crs (src_epsg .value ,
158
140
tgt_epsg .value )
159
141
142
+ #TODO
160
143
def geo_and_pixel (self , src_epsg , geojson ):
161
144
pass
162
145
0 commit comments