3636)
3737
3838BOX_ORD = "(west, south, east, north)"
39- NUMBER = Union [int , float , np .number ] # pyright: ignore[reportMissingTypeArgument]
4039if TYPE_CHECKING :
4140 from collections .abc import Generator , Iterable
4241
4342 from numpy .typing import NDArray
43+ from pyproj import CRS
4444 from rasterio .io import DatasetReader
4545
46- GTYPE = Union [Polygon , MultiPolygon , tuple [float , float , float , float ]]
47- GDFTYPE = TypeVar ("GDFTYPE" , gpd .GeoDataFrame , gpd .GeoSeries )
48- XD = TypeVar ("XD" , xr .Dataset , xr .DataArray )
49- CRSTYPE = Union [int , str , pyproj .CRS ]
50-
51- FloatArray = NDArray [np .float64 ]
46+ CRSType = int | str | CRS
47+ GeoType = Polygon | MultiPolygon | tuple [float , float , float , float ]
48+ GeoDFType = TypeVar ("GeoDFType" , gpd .GeoDataFrame , gpd .GeoSeries )
49+ DataArray = TypeVar ("DataArray" , xr .Dataset , xr .DataArray )
50+ Number = Union [int , float , np .number ] # pyright: ignore[reportMissingTypeArgument]
5251
5352__all__ = [
5453 "arcgis2geojson" ,
@@ -103,8 +102,8 @@ def _gdf_from_features(
103102
104103def json2geodf (
105104 content : list [dict [str , Any ]] | dict [str , Any ],
106- in_crs : CRSTYPE | None = 4326 ,
107- crs : CRSTYPE | None = 4326 ,
105+ in_crs : CRSType | None = 4326 ,
106+ crs : CRSType | None = 4326 ,
108107) -> gpd .GeoDataFrame :
109108 """Create GeoDataFrame from (Geo)JSON.
110109
@@ -153,13 +152,13 @@ def json2geodf(
153152
154153
155154def xarray_geomask (
156- ds : XD ,
157- geometry : GTYPE ,
158- crs : CRSTYPE ,
155+ ds : DataArray ,
156+ geometry : GeoType ,
157+ crs : CRSType ,
159158 all_touched : bool = False ,
160159 drop : bool = True ,
161160 from_disk : bool = False ,
162- ) -> XD :
161+ ) -> DataArray :
163162 """Mask a ``xarray.Dataset`` based on a geometry.
164163
165164 Parameters
@@ -217,8 +216,8 @@ def _to_dataset(
217216 var_name : str ,
218217 driver : str | None ,
219218 dtypes : dict [str , np .dtype ], # pyright: ignore[reportMissingTypeArgument]
220- nodata_dict : dict [str , NUMBER ],
221- nodata : NUMBER | None ,
219+ nodata_dict : dict [str , Number ],
220+ nodata : Number | None ,
222221) -> xr .DataArray :
223222 with MemoryFile () as memfile :
224223 memfile .write (resp )
@@ -236,12 +235,12 @@ def _to_dataset(
236235
237236def gtiff2xarray (
238237 r_dict : dict [str , bytes ],
239- geometry : GTYPE | None = None ,
240- geo_crs : CRSTYPE | None = None ,
238+ geometry : GeoType | None = None ,
239+ geo_crs : CRSType | None = None ,
241240 ds_dims : tuple [str , str ] | None = None ,
242241 driver : str | None = None ,
243242 all_touched : bool = False ,
244- nodata : NUMBER | None = None ,
243+ nodata : Number | None = None ,
245244 drop : bool = True ,
246245) -> xr .DataArray | xr .Dataset :
247246 """Convert (Geo)Tiff byte responses to ``xarray.Dataset``.
@@ -296,7 +295,7 @@ def gtiff2xarray(
296295
297296 attrs = utils .get_gtiff_attrs (r_dict [key1 ], ds_dims , driver , nodata )
298297 dtypes : dict [str , np .dtype ] = {} # pyright: ignore[reportMissingTypeArgument]
299- nodata_dict : dict [str , NUMBER ] = {}
298+ nodata_dict : dict [str , Number ] = {}
300299
301300 ds = xr .merge (
302301 _to_dataset (resp , var_name [lyr ], driver , dtypes , nodata_dict , nodata )
@@ -421,11 +420,11 @@ def xarray2geodf(
421420
422421
423422def geodf2xarray (
424- geodf : GDFTYPE ,
423+ geodf : GeoDFType ,
425424 resolution : float ,
426425 attr_col : str | None = None ,
427426 fill : float = 0 ,
428- projected_crs : CRSTYPE = 5070 ,
427+ projected_crs : CRSType = 5070 ,
429428) -> xr .Dataset :
430429 """Rasterize a ``geopandas.GeoDataFrame`` to ``xarray.DataArray``.
431430
@@ -521,7 +520,7 @@ def sample_window(
521520 indexes : int | list [int ] | None = None ,
522521 masked : bool = False ,
523522 resampling : int = 1 ,
524- ) -> Generator [FloatArray , None , None ]:
523+ ) -> Generator [NDArray [ np . float64 ] , None , None ]:
525524 """Interpolate pixel values at given coordinates by interpolation.
526525
527526 .. note::
0 commit comments