Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions stubs/rasterio/@tests/test_cases/check_crs_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import annotations

from typing_extensions import assert_type

import rasterio.warp
from rasterio.crs import CRS
from rasterio.io import MemoryFile


class ForeignCRS:
def to_wkt(self) -> str:
return ""


assert_type(rasterio.warp.transform_bounds(4326, 3857, 0.0, 0.0, 1.0, 1.0), tuple[float, float, float, float])
rasterio.warp.transform_bounds(ForeignCRS(), ForeignCRS(), 0.0, 0.0, 1.0, 1.0)
rasterio.warp.transform_bounds(CRS.from_epsg(4326), "EPSG:3857", 0.0, 0.0, 1.0, 1.0)
rasterio.warp.transform_bounds({"init": "EPSG:4326"}, CRS.from_epsg(3857), 0.0, 0.0, 1.0, 1.0)
rasterio.warp.transform_bounds(object(), 3857, 0.0, 0.0, 1.0, 1.0) # type: ignore
rasterio.warp.transform(4326, ForeignCRS(), [0.0], [0.0])
rasterio.warp.calculate_default_transform(4326, ForeignCRS(), 10, 10, left=0.0, bottom=0.0, right=1.0, top=1.0)
MemoryFile().open(driver="GTiff", width=1, height=1, count=1, dtype="uint8", crs=4326)
MemoryFile().open(driver="GTiff", width=1, height=1, count=1, dtype="uint8", crs=ForeignCRS())
8 changes: 7 additions & 1 deletion stubs/rasterio/rasterio/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ class _SupportsGeoInterface(Protocol):
@property
def __geo_interface__(self) -> Mapping[str, Any]: ...

@type_check_only
class _SupportsToWkt(Protocol):
def to_wkt(self) -> str: ...

# A GeoJSON-like mapping, or any object exposing one through the
# `__geo_interface__` protocol (e.g. shapely / geopandas geometries).
# The runtime unwraps `__geo_interface__` before use, so both forms are
# accepted anywhere a geometry is expected.
Geometry: TypeAlias = Mapping[str, Any] | _SupportsGeoInterface # noqa: Y047
Colormap: TypeAlias = dict[int, tuple[int, int, int] | tuple[int, int, int, int]]
CRSInput: TypeAlias = str | dict[str, str] | CRS
# A WKT / PROJ string, an EPSG code, a PROJ dict, or any object exposing
# `to_wkt` (e.g. a pyproj CRS). `CRS.from_user_input` normalizes all of them.
CRSInput: TypeAlias = str | int | dict[str, str] | CRS | _SupportsToWkt
FileOrBytes: TypeAlias = BinaryIO | bytes
Indexes: TypeAlias = int | Sequence[int]
NumType: TypeAlias = int | float
Expand Down