11from dataclasses import dataclass
22from enum import Enum
33from typing import Literal , TypeAlias , TypedDict
4+ from warnings import warn
45
56from shapely import Geometry , from_wkb , to_wkb
67
1516
1617class SpatialFilterMode (Enum ):
1718 INTERSECTS = data_access_pb2 .SPATIAL_FILTER_MODE_INTERSECTS
18- CONTAINS = data_access_pb2 .SPATIAL_FILTER_MODE_CONTAINS
19+ FILTER_CONTAINS_GEOMETRY = data_access_pb2 .SPATIAL_FILTER_MODE_FILTER_CONTAINS_GEOMETRY
20+ GEOMETRY_CONTAINS_FILTER = data_access_pb2 .SPATIAL_FILTER_MODE_GEOMETRY_CONTAINS_FILTER
1921
2022
2123_filter_modes_from_string = {mode .name .lower (): mode for mode in SpatialFilterMode }
@@ -33,7 +35,10 @@ class SpatialCoordinateSystem(Enum):
3335
3436class SpatialFilterDict (TypedDict ):
3537 geometry : Geometry
36- mode : NotRequired [SpatialFilterMode | Literal ["intersects" , "contains" ]]
38+ # "contains" is deprecated and retained only for backwards compatibility.
39+ mode : NotRequired [
40+ SpatialFilterMode | Literal ["intersects" , "filter_contains_geometry" , "geometry_contains_filter" , "contains" ]
41+ ]
3742 coordinate_system : NotRequired [SpatialCoordinateSystem | Literal ["cartesian" , "spherical" ]]
3843
3944
@@ -49,8 +54,8 @@ class SpatialFilter:
4954
5055 Args:
5156 geometry: The spatial geometry to filter by (e.g. a polygon)
52- mode: The spatial filter mode to use. Can be one of "intersects" or "contains".
53- Defaults to "intersects".
57+ mode: The spatial filter mode to use. Can be one of "intersects", "filter_contains_geometry", or
58+ "geometry_contains_filter". Defaults to "intersects".
5459 crs: The coordinate system to use for performing geometry calculations. Can be one
5560 of "cartesian" or "spherical".
5661 """
@@ -92,6 +97,13 @@ def parse(cls, spatial_filter_like: SpatialFilterLike) -> "SpatialFilter":
9297 if isinstance (spatial_filter_like , dict ):
9398 mode = spatial_filter_like .get ("mode" , None )
9499 if isinstance (mode , str ):
100+ if mode .lower () == "contains" :
101+ warn (
102+ 'The spatial filter mode "contains" is deprecated. Use "filter_contains_geometry" instead.' ,
103+ DeprecationWarning ,
104+ stacklevel = 2 ,
105+ )
106+ mode = "filter_contains_geometry"
95107 mode = _filter_modes_from_string .get (mode .lower ())
96108 coordinate_system = spatial_filter_like .get ("coordinate_system" , None )
97109 if isinstance (coordinate_system , str ):
0 commit comments