brails.types.region_boundary module
This module defines RegionBoundary class to store region boundary polygons.
|
A class for retrieving the bounding polygon of a specified region. |
- class brails.types.region_boundary.RegionBoundary(input_dict: Dict[str, Any] | None = None)
Bases:
object
A class for retrieving the bounding polygon of a specified region.
This class processes input data, validates it, and provides functionality to obtain the region boundary based on the given data. The input must specify the type of region (e.g., location name or polygon) and the corresponding data.
- Attributes:
- type (str):
The type of the region (e.g., ‘locationName’, ‘locationPolygon’).
- data (str or tuple):
The data associated with the region, validated according to the specified type. Either a location name, e.g., ‘Berkeley, CA’, or a tuple, such as (-93.27968, 30.22733, -93.14492, 30.15774)
- Methods:
- get_boundary():
Returns the boundary polygon of the specified region.
- get_boundary() Tuple[BaseGeometry, str, int | str | None]
Return the boundary of the region based on the provided input type.
This method processes the region’s data based on its type and returns the corresponding boundary. If the type is ‘locationName’, it fetches the region boundary from an external data source. If the type is ‘locationPolygon’, it converts the provided coordinates (bounding box) into a Shapely polygon.
- Returns:
- Tuple[BaseGeometry, str, Optional[Union[int, str]]]:
A Shapely geometry object representing the region boundary.
A human-readable description of the query area.
An optional OSM ID (or similar identifier) for the boundary, if available.
- Raises:
- ValueError: If the input data type is not ‘locationName’ or
‘locationPolygon’, or if the data is invalid for the given type.
- class brails.types.region_boundary.RegionInput(dataType: type, validationConditions: Callable, errorMessage: str)
Bases:
object
Input configuration for a specific region type.
- Attributes:
- dataType (type):
The expected data type for the input (e.g., str, tuple).
- validationConditions (function):
A function that validates the input data based on the expected data type.
- errorMessage (str):
The error message to be raised when the validation fails for the input data.
- Example:
- location_name_input = RegionInput(
dataType=str, validationConditions=lambda data, dataType: isinstance(data,
dataType),
errorMessage=“‘data’ must be a string”
)
- dataType: type
- errorMessage: str
- validationConditions: Callable