|
| 1 | +import builtins |
| 2 | +from _typeshed import Incomplete, Unused |
| 3 | +from collections.abc import Callable, Sequence |
| 4 | +from typing import Any, ClassVar, Literal, NoReturn, SupportsIndex, TypeVar, overload |
| 5 | +from typing_extensions import Self, TypeAlias, deprecated |
| 6 | + |
| 7 | +import numpy as np |
| 8 | +import pandas as pd |
| 9 | +from numpy.typing import ArrayLike, DTypeLike, NDArray |
| 10 | +from pandas.api.extensions import ExtensionArray, ExtensionDtype |
| 11 | +from pyproj import CRS, Transformer |
| 12 | +from shapely import Geometry |
| 13 | +from shapely.geometry.base import BaseGeometry |
| 14 | + |
| 15 | +from .base import _AffinityOrigin, _ConvertibleToCRS |
| 16 | +from .sindex import SpatialIndex |
| 17 | + |
| 18 | +_ScalarType = TypeVar("_ScalarType", bound=np.generic) |
| 19 | +_Array1D: TypeAlias = np.ndarray[tuple[int], np.dtype[_ScalarType]] |
| 20 | +_Array2D: TypeAlias = np.ndarray[tuple[int, int], np.dtype[_ScalarType]] |
| 21 | +_ArrayOrGeom: TypeAlias = GeometryArray | ArrayLike | Geometry |
| 22 | + |
| 23 | +TransformerFromCRS = Transformer.from_crs |
| 24 | + |
| 25 | +class GeometryDtype(ExtensionDtype): |
| 26 | + type: ClassVar[type[BaseGeometry]] |
| 27 | + name: ClassVar[str] |
| 28 | + na_value: float |
| 29 | + @classmethod |
| 30 | + def construct_from_string(cls, string: str) -> Self: ... |
| 31 | + @classmethod |
| 32 | + def construct_array_type(cls) -> builtins.type[GeometryArray]: ... |
| 33 | + |
| 34 | +def isna(value: object) -> bool: ... |
| 35 | +def from_shapely(data, crs: _ConvertibleToCRS | None = None) -> GeometryArray: ... |
| 36 | +def to_shapely(geoms: GeometryArray) -> _Array1D[np.object_]: ... |
| 37 | +def from_wkb( |
| 38 | + data, crs: _ConvertibleToCRS | None = None, on_invalid: Literal["raise", "warn", "ignore"] = "raise" |
| 39 | +) -> GeometryArray: ... |
| 40 | +@overload |
| 41 | +def to_wkb(geoms: GeometryArray, hex: Literal[False] = False, **kwargs) -> _Array1D[np.bytes_]: ... |
| 42 | +@overload |
| 43 | +def to_wkb(geoms: GeometryArray, hex: Literal[True], **kwargs) -> _Array1D[np.str_]: ... |
| 44 | +def from_wkt( |
| 45 | + data, crs: _ConvertibleToCRS | None = None, on_invalid: Literal["raise", "warn", "ignore"] = "raise" |
| 46 | +) -> GeometryArray: ... |
| 47 | +def to_wkt(geoms: GeometryArray, **kwargs) -> _Array1D[np.str_]: ... |
| 48 | +def points_from_xy( |
| 49 | + x: ArrayLike, y: ArrayLike, z: ArrayLike | None = None, crs: _ConvertibleToCRS | None = None |
| 50 | +) -> GeometryArray: ... |
| 51 | + |
| 52 | +class GeometryArray(ExtensionArray): |
| 53 | + def __init__(self, data: GeometryArray | NDArray[np.object_], crs: _ConvertibleToCRS | None = None) -> None: ... |
| 54 | + @property |
| 55 | + def sindex(self) -> SpatialIndex: ... |
| 56 | + @property |
| 57 | + def has_sindex(self) -> bool: ... |
| 58 | + @property |
| 59 | + def crs(self) -> CRS | None: ... |
| 60 | + @crs.setter |
| 61 | + def crs(self, value: _ConvertibleToCRS | None) -> None: ... |
| 62 | + def check_geographic_crs(self, stacklevel: int) -> None: ... |
| 63 | + @property |
| 64 | + def dtype(self) -> GeometryDtype: ... |
| 65 | + def __len__(self) -> int: ... |
| 66 | + # np.integer[Any] because precision is not important |
| 67 | + @overload |
| 68 | + def __getitem__(self, idx: int | np.integer[Any]) -> BaseGeometry: ... # Always 1-D, doesn't accept tuple |
| 69 | + @overload |
| 70 | + def __getitem__( |
| 71 | + self, idx: slice | Sequence[SupportsIndex] | NDArray[np.bool_] | NDArray[np.integer[Any]] |
| 72 | + ) -> GeometryArray: ... |
| 73 | + @overload |
| 74 | + def __getitem__( |
| 75 | + self, idx: int | np.integer[Any] | slice | Sequence[int] | NDArray[np.bool_] | NDArray[np.integer[Any]] |
| 76 | + ) -> BaseGeometry | GeometryArray: ... |
| 77 | + def __setitem__( |
| 78 | + self, key, value: _ArrayOrGeom | pd.DataFrame | pd.Series[Any] # Cannot use pd.Series[BaseGeometry] |
| 79 | + ) -> None: ... |
| 80 | + @property |
| 81 | + def is_valid(self) -> _Array1D[np.bool_]: ... |
| 82 | + def is_valid_reason(self) -> _Array1D[np.object_]: ... |
| 83 | + @property |
| 84 | + def is_empty(self) -> _Array1D[np.bool_]: ... |
| 85 | + @property |
| 86 | + def is_simple(self) -> _Array1D[np.bool_]: ... |
| 87 | + @property |
| 88 | + def is_ring(self) -> _Array1D[np.bool_]: ... |
| 89 | + @property |
| 90 | + def is_closed(self) -> _Array1D[np.bool_]: ... |
| 91 | + @property |
| 92 | + def is_ccw(self) -> _Array1D[np.bool_]: ... |
| 93 | + @property |
| 94 | + def has_z(self) -> _Array1D[np.bool_]: ... |
| 95 | + @property |
| 96 | + def geom_type(self) -> _Array1D[np.str_]: ... |
| 97 | + @property |
| 98 | + def area(self) -> _Array1D[np.float64]: ... |
| 99 | + @property |
| 100 | + def length(self) -> _Array1D[np.float64]: ... |
| 101 | + def count_coordinates(self) -> _Array1D[np.int32]: ... |
| 102 | + def count_geometries(self) -> _Array1D[np.int32]: ... |
| 103 | + def count_interior_rings(self) -> _Array1D[np.int32]: ... |
| 104 | + def get_precision(self) -> _Array1D[np.float64]: ... |
| 105 | + def get_geometry(self, index: SupportsIndex | ArrayLike) -> _Array1D[np.object_]: ... |
| 106 | + @property |
| 107 | + def boundary(self) -> GeometryArray: ... |
| 108 | + @property |
| 109 | + def centroid(self) -> GeometryArray: ... |
| 110 | + def concave_hull(self, ratio: float, allow_holes: bool) -> _Array1D[np.object_]: ... |
| 111 | + @property |
| 112 | + def convex_hull(self) -> GeometryArray: ... |
| 113 | + @property |
| 114 | + def envelope(self) -> GeometryArray: ... |
| 115 | + def minimum_rotated_rectangle(self) -> GeometryArray: ... |
| 116 | + @property |
| 117 | + def exterior(self) -> GeometryArray: ... |
| 118 | + def extract_unique_points(self) -> GeometryArray: ... |
| 119 | + def offset_curve( |
| 120 | + self, |
| 121 | + distance: float | ArrayLike, |
| 122 | + quad_segs: int = 8, |
| 123 | + join_style: Literal["round", "bevel", "mitre"] = "round", |
| 124 | + mitre_limit: float = 5.0, |
| 125 | + ) -> GeometryArray: ... |
| 126 | + @property |
| 127 | + def interiors(self) -> _Array1D[np.object_]: ... |
| 128 | + def remove_repeated_points(self, tolerance: float | ArrayLike = 0.0) -> GeometryArray: ... |
| 129 | + def representative_point(self) -> GeometryArray: ... |
| 130 | + def minimum_bounding_circle(self) -> GeometryArray: ... |
| 131 | + def minimum_bounding_radius(self) -> _Array1D[np.float64]: ... |
| 132 | + def minimum_clearance(self) -> _Array1D[np.float64]: ... |
| 133 | + def normalize(self) -> GeometryArray: ... |
| 134 | + def make_valid(self) -> GeometryArray: ... |
| 135 | + def reverse(self) -> GeometryArray: ... |
| 136 | + def segmentize(self, max_segment_length: float | ArrayLike) -> GeometryArray: ... |
| 137 | + def force_2d(self) -> GeometryArray: ... |
| 138 | + def force_3d(self, z: float | ArrayLike = 0) -> GeometryArray: ... |
| 139 | + def transform( |
| 140 | + self, transformation: Callable[[NDArray[np.float64]], NDArray[np.float64]], include_z: bool = False |
| 141 | + ) -> GeometryArray: ... |
| 142 | + def line_merge(self, directed: bool = False) -> GeometryArray: ... |
| 143 | + def set_precision( |
| 144 | + self, grid_size: float, mode: Literal["valid_output", "pointwise", "keep_collapsed", 0, 1, 2] = "valid_output" |
| 145 | + ) -> GeometryArray: ... |
| 146 | + def covers(self, other: _ArrayOrGeom) -> _Array1D[np.bool_]: ... |
| 147 | + def covered_by(self, other: _ArrayOrGeom) -> _Array1D[np.bool_]: ... |
| 148 | + def contains(self, other: _ArrayOrGeom) -> _Array1D[np.bool_]: ... |
| 149 | + def contains_properly(self, other: _ArrayOrGeom) -> _Array1D[np.bool_]: ... |
| 150 | + def crosses(self, other: _ArrayOrGeom) -> _Array1D[np.bool_]: ... |
| 151 | + def disjoint(self, other: _ArrayOrGeom) -> _Array1D[np.bool_]: ... |
| 152 | + def geom_equals(self, other: _ArrayOrGeom) -> _Array1D[np.bool_]: ... |
| 153 | + def intersects(self, other: _ArrayOrGeom) -> _Array1D[np.bool_]: ... |
| 154 | + def overlaps(self, other: _ArrayOrGeom) -> _Array1D[np.bool_]: ... |
| 155 | + def touches(self, other: _ArrayOrGeom) -> _Array1D[np.bool_]: ... |
| 156 | + def within(self, other: _ArrayOrGeom) -> _Array1D[np.bool_]: ... |
| 157 | + def dwithin(self, other: _ArrayOrGeom, distance: float) -> _Array1D[np.bool_]: ... |
| 158 | + def geom_equals_exact(self, other: _ArrayOrGeom, tolerance: float | ArrayLike) -> _Array1D[np.bool_]: ... |
| 159 | + @deprecated("Use method `geom_equals_exact` instead.") |
| 160 | + def geom_almost_equals(self, other: _ArrayOrGeom, decimal: float) -> _Array1D[np.bool_]: ... |
| 161 | + def clip_by_rect(self, xmin: float, ymin: float, xmax: float, ymax: float) -> GeometryArray: ... |
| 162 | + def difference(self, other: _ArrayOrGeom) -> GeometryArray: ... |
| 163 | + def intersection(self, other: _ArrayOrGeom) -> GeometryArray: ... |
| 164 | + def symmetric_difference(self, other: _ArrayOrGeom) -> GeometryArray: ... |
| 165 | + def union(self, other: _ArrayOrGeom) -> GeometryArray: ... |
| 166 | + def shortest_line(self, other: _ArrayOrGeom) -> GeometryArray: ... |
| 167 | + def snap(self, other: _ArrayOrGeom, tolerance: float | ArrayLike) -> GeometryArray: ... |
| 168 | + def shared_paths(self, other: _ArrayOrGeom) -> GeometryArray: ... |
| 169 | + def distance(self, other: _ArrayOrGeom) -> _Array1D[np.float64]: ... |
| 170 | + def hausdorff_distance(self, other: _ArrayOrGeom, **kwargs) -> _Array1D[np.float64]: ... |
| 171 | + def frechet_distance(self, other: _ArrayOrGeom, **kwargs) -> _Array1D[np.float64]: ... |
| 172 | + def buffer(self, distance: float | ArrayLike, resolution: int = 16, **kwargs) -> GeometryArray: ... |
| 173 | + def interpolate(self, distance: float | ArrayLike, normalized: bool = False) -> GeometryArray: ... |
| 174 | + def simplify(self, tolerance: float | ArrayLike, preserve_topology: bool = True) -> GeometryArray: ... |
| 175 | + def project(self, other: _ArrayOrGeom, normalized: bool = False) -> _Array1D[np.float64]: ... |
| 176 | + def relate(self, other: _ArrayOrGeom) -> _Array1D[np.str_]: ... |
| 177 | + def relate_pattern(self, other: _ArrayOrGeom, pattern: str) -> _Array1D[np.bool_]: ... |
| 178 | + @deprecated("Use method `union_all` instead.") |
| 179 | + def unary_union(self) -> BaseGeometry: ... |
| 180 | + def union_all(self, method: Literal["coverage", "unary"] = "unary") -> BaseGeometry: ... |
| 181 | + def intersection_all(self) -> BaseGeometry: ... |
| 182 | + def affine_transform(self, matrix) -> GeometryArray: ... |
| 183 | + def translate(self, xoff: float = 0.0, yoff: float = 0.0, zoff: float = 0.0) -> GeometryArray: ... |
| 184 | + def rotate(self, angle: float, origin: _AffinityOrigin = "center", use_radians: bool = False) -> GeometryArray: ... |
| 185 | + def scale( |
| 186 | + self, xfact: float = 1.0, yfact: float = 1.0, zfact: float = 1.0, origin: _AffinityOrigin = "center" |
| 187 | + ) -> GeometryArray: ... |
| 188 | + def skew( |
| 189 | + self, xs: float = 0.0, ys: float = 0.0, origin: _AffinityOrigin = "center", use_radians: bool = False |
| 190 | + ) -> GeometryArray: ... |
| 191 | + def to_crs(self, crs: _ConvertibleToCRS | None = None, epsg: int | None = None) -> GeometryArray: ... |
| 192 | + def estimate_utm_crs(self, datum_name: str = "WGS 84") -> CRS: ... |
| 193 | + @property |
| 194 | + def x(self) -> _Array1D[np.float64]: ... |
| 195 | + @property |
| 196 | + def y(self) -> _Array1D[np.float64]: ... |
| 197 | + @property |
| 198 | + def z(self) -> _Array1D[np.float64]: ... |
| 199 | + @property |
| 200 | + def bounds(self) -> _Array2D[np.float64]: ... |
| 201 | + @property |
| 202 | + def total_bounds(self) -> _Array1D[np.float64]: ... |
| 203 | + @property |
| 204 | + def size(self) -> int: ... |
| 205 | + @property |
| 206 | + def shape(self) -> tuple[int]: ... # Always 1-D, this is not a mistake |
| 207 | + @property |
| 208 | + def ndim(self) -> Literal[1]: ... |
| 209 | + def copy(self, *args: Unused, **kwargs: Unused) -> GeometryArray: ... |
| 210 | + def take( |
| 211 | + self, |
| 212 | + indices: Sequence[SupportsIndex] | NDArray[np.integer[Any]], # np.integer[Any] because precision is not important |
| 213 | + allow_fill: bool = False, |
| 214 | + fill_value: Geometry | None = None, |
| 215 | + ) -> GeometryArray: ... |
| 216 | + def fillna( |
| 217 | + self, |
| 218 | + value: Geometry | GeometryArray | None = None, |
| 219 | + method: Literal["backfill", "bfill", "pad", "ffill"] | None = None, |
| 220 | + limit: int | None = None, |
| 221 | + copy: bool = True, |
| 222 | + ) -> GeometryArray: ... |
| 223 | + @overload |
| 224 | + def astype(self, dtype: GeometryDtype, copy: bool = True) -> GeometryArray: ... |
| 225 | + @overload |
| 226 | + def astype(self, dtype: ExtensionDtype | Literal["string"], copy: bool = True) -> ExtensionArray: ... # type: ignore[overload-overlap] |
| 227 | + @overload |
| 228 | + def astype(self, dtype: DTypeLike, copy: bool = True) -> _Array1D[Incomplete]: ... |
| 229 | + def isna(self) -> _Array1D[np.bool_]: ... |
| 230 | + def value_counts(self, dropna: bool = True) -> pd.Series[int]: ... |
| 231 | + def unique(self) -> GeometryArray: ... |
| 232 | + @property |
| 233 | + def nbytes(self) -> int: ... |
| 234 | + def shift(self, periods: int = 1, fill_value: Geometry | None = None) -> GeometryArray: ... # type: ignore[override] |
| 235 | + def argmin(self, skipna: bool = True) -> NoReturn: ... |
| 236 | + def argmax(self, skipna: bool = True) -> NoReturn: ... |
| 237 | + def __array__(self, dtype: DTypeLike | None = None, copy: bool | None = None) -> _Array1D[np.object_]: ... |
| 238 | + def __eq__(self, other: object) -> _Array1D[np.bool_]: ... # type: ignore[override] |
| 239 | + def __ne__(self, other: object) -> _Array1D[np.bool_]: ... # type: ignore[override] |
| 240 | + def __contains__(self, item: object) -> np.bool_: ... |
| 241 | + |
| 242 | +def transform( |
| 243 | + data: NDArray[np.object_], func: Callable[[NDArray[np.float64], NDArray[np.float64]], NDArray[np.float64]] |
| 244 | +) -> NDArray[np.object_]: ... |
0 commit comments