brails.utils.input_validator module

This module provides a utility class for validating input data in BRAILS.

InputValidator()

A utility class for validating BRAILS geospatial input data.

class brails.utils.input_validator.InputValidator

Bases: object

A utility class for validating BRAILS geospatial input data.

This class provides static methods to validate various geospatial data structures such as points, linestrings, polygons, and their multi-geometries, ensuring conformance with geographic coordinate standards (longitude/latitude).

It also includes a lightweight utility for checking whether a file path points to an image file based on its extension, without opening the file.

All methods are designed to validate nested lists of floats representing coordinates, with specific rules for each geometry type.

Methods:
is_float(input_value: Any) -> bool:

Checks whether a given value can be safely converted to a float.

validate_coordinates(coordinates: List[List[float]])->Tuple[bool, str]:

Validates a nested list of coordinates, ensuring correct structure and ranges for longitude (-180 to 180) and latitude (-90 to 90).

is_valid_geometry(coordinates: List[List[float]]) -> bool:

Returns whether the input coordinates pass the base validation check.

is_point(coordinates: List[List[float]]) -> bool:

Returns True if the coordinates represent a valid single-point geometry.

is_linestring(coordinates: List[List[float]]) -> bool:

Returns True if the coordinates represent a valid LineString (at least two distinct points and not closed).

is_multilinestring(coordinates: List[List[List[float]]]) -> bool:

Returns True if the coordinates represent a MultiLineString composed of valid LineStrings.

is_polygon(coordinates: List[List[float]]) -> bool:

Returns True if the coordinates form a valid Polygon (closed loop with at least 3 points).

is_multipolygon(coordinates: List[List[List[float]]]) -> bool:

Returns True if the coordinates form a valid MultiPolygon (a list of valid Polygons).

is_image(filepath: str) -> bool:

Returns True if the given path points to a file that exists and has a valid image file extension (‘.jpg’, ‘.jpeg’, ‘.png’, ‘.bmp’). This method does not read or load the image file.

static is_float(input_value: Any) bool

Check if the given input_value can be converted to a float.

Args:
input_value (Any):

The input_value to check.

Returns:
bool:

True if the input_value can be converted to a float, False otherwise.

static is_image(filepath: str) bool

Perform a lightweight check to determine if the file is an image.

This function checks that the path exists, is a file, and has a valid image file extension. It does not open or validate the contents of the file, so it cannot detect corrupted or mislabeled files.

Args:
filepath (str):

The path to the file to check.

Returns:
bool:

True if the path points to a file with a supported image extension, otherwise False.

static is_linestring(coordinates: List[List[float]]) bool

Determine whether the given coordinates represent a linestring.

In BRAILS, a linestring is defined as a sequence of at least two coordinate pairs, and it is not closed (the first and last points are different). If exactly two points are provided, it is considered a valid linestring

Args:
coordinates (list[list[float]]):

A list of coordinate pairs forming a linestring.

Returns:
bool:

True if the coordinates represent a linestring, False otherwise.

static is_multilinestring(coordinates: List[List[List[float]]]) bool

Determine whether the given coordinates represent a MultiLineString.

In BRAILS, a MultiLineString is defined as a list of valid linestrings, each with at least 2 points and not forming a closed loop.

Args:
coordinates (list[list[list[float]]]):

A list of linestrings, each represented as a list of coordinate pairs.

Returns:
bool:

True if the coordinates represent a MultiLineString, False otherwise.

static is_multipolygon(coordinates: List[List[List[float]]]) bool

Determine whether the given coordinates represent a MultiPolygon.

In BRAILS, a MultiPolygon is defined as a list of valid polygons, where each polygon is a closed loop with at least 3 points.

Args:
coordinates (list[list[list[float]]]):

A list of polygons, each represented as a list of coordinate pairs.

Returns:
bool:

True if the coordinates represent a MultiPolygon, False otherwise.

static is_point(coordinates: List[List[float]]) bool

Determine whether the given coordinates represent a point.

In BRAILS, a point is defined as a single coordinate pair.

Args:
coordinates (list[list[float]]):

A list containing coordinate pairs [latitude, longitude].

Returns:
bool:

True if the coordinates represent a point, False otherwise.

static is_polygon(coordinates: List[List[float]]) bool

Determine whether the given coordinates represent a polygon.

In BRAILS, a polygon is defined as a sequence of at least three coordinate pairs where the first and last coordinates are the same (closed loop).

Args:
coordinates (list[list[float]]):

A list of coordinate pairs forming a polygon.

Returns:
bool:

True if the coordinates represent a polygon, False otherwise.

static is_valid_geometry(coordinates: List[List[float]]) bool

Validate whether the given coordinates represent a valid geometry.

Args:
coordinates (list[list[float]]):

A list of coordinate pairs.

Returns:
bool:

True if the coordinates are valid, False otherwise.

static validate_coordinates(coordinates: List[List[float]]) Tuple[bool, str]

Validate input for coordinates.

Args:
coordinates (list[list[float]]):

A two-dimensional list representing the geometry in [[lon1, lat1], [lon2, lat2], …, [lonN, latN]] format.

Returns:
tuple[bool, str]:

A tuple containing: - A boolean indicating if all coordinates are valid. - A message string describing any issues found, or confirming

validation success.