"""This module contains the structures related to areas of interest."""fromdataclassesimportdataclassfromtypingimportNamedTuple,Unionfrompyproj.utilsimportis_null
[docs]@dataclass(frozen=True)classAreaOfInterest:""" .. versionadded:: 2.3.0 This is the area of interest for: - Transformations - Querying for CRS data. """#: The west bound in degrees of the area of interest.west_lon_degree:float#: The south bound in degrees of the area of interest.south_lat_degree:float#: The east bound in degrees of the area of interest.east_lon_degree:float#: The north bound in degrees of the area of interest.north_lat_degree:floatdef__post_init__(self):if(is_null(self.west_lon_degree)oris_null(self.south_lat_degree)oris_null(self.east_lon_degree)oris_null(self.north_lat_degree)):raiseValueError("NaN or None values are not allowed.")
[docs]classAreaOfUse(NamedTuple):""" .. versionadded:: 2.0.0 Area of Use for CRS, CoordinateOperation, or a Transformer. """#: West bound of area of use.west:float#: South bound of area of use.south:float#: East bound of area of use.east:float#: North bound of area of use.north:float#: Name of area of use.name:str|None=None@propertydefbounds(self)->tuple[float,float,float,float]:""" The bounds of the area of use. Returns ------- tuple[float, float, float, float] west, south, east, and north bounds. """returnself.west,self.south,self.east,self.northdef__str__(self)->str:returnf"- name: {self.name}\n- bounds: {self.bounds}"
[docs]@dataclassclassBBox:""" Bounding box to check if data intersects/contains other bounding boxes. .. versionadded:: 3.0.0 """#: West bound of bounding box.west:float#: South bound of bounding box.south:float#: East bound of bounding box.east:float#: North bound of bounding box.north:floatdef__post_init__(self):if(is_null(self.west)oris_null(self.south)oris_null(self.east)oris_null(self.north)):raiseValueError("NaN or None values are not allowed.")
[docs]defintersects(self,other:Union["BBox",AreaOfUse])->bool:""" Parameters ---------- other: BBox The other BBox to use to check. Returns ------- bool: True if this BBox intersects the other bbox. """return(self.west<other.eastandother.west<self.eastandself.south<other.northandother.south<self.north)
[docs]defcontains(self,other:Union["BBox",AreaOfUse])->bool:""" Parameters ---------- other: Union["BBox", AreaOfUse] The other BBox to use to check. Returns ------- bool: True if this BBox contains the other bbox. """return(other.west>=self.westandother.east<=self.eastandother.south>=self.southandother.north<=self.north)