windkit.check_lines_cross
- windkit.check_lines_cross(lines_out, errors='raise', add_errors=False)[source]
Detects and handles crossing line geometries in a GeoDataFrame.
This function identifies line geometries that cross each other in the input GeoDataFrame. It can raise an error, issue a warning, or add a boolean column indicating crossing lines.
- Parameters:
lines_out (geopandas.GeoDataFrame) – A GeoDataFrame containing line geometries to check for crossings.
errors ({"raise", "warn", "ignore"}, optional) – Specifies how to handle detected crossings: - “raise”: Raises a ‘ValueError’ if crossings are found. - “warn”: Issues a warning if crossings are found. - “ignore”: Does nothing. Default is “raise”.
add_errors (bool, optional) – If True, adds a boolean column named “crosses” to the input GeoDataFrame, indicating whether each line crosses another line. Default is True.
- Returns:
The input GeoDataFrame with an optional “crosses” column added if ‘add_errors’ is True.
- Return type:
- Raises:
ValueError – If ‘errors’ is set to “raise” and crossing lines are detected.
- Warns:
UserWarning – If ‘errors’ is set to “warn” and crossing lines are detected.
Notes
The function first uses a spatial join to detect crossings. If crossings are found, it performs a more precise check by splitting the lines into segments and rechecking for overlaps.
This secondary check is slower and is only performed if crossings are initially detected.
Examples
>>> import geopandas as gpd >>> from shapely.geometry import LineString >>> lines = gpd.GeoDataFrame({ ... "geometry": [LineString([(0, 0), (1, 1)]), LineString([(0, 1), (1, 0)])] ... }) >>> check_lines_cross(lines, errors="warn") GeoDataFrame with a "crosses" column indicating crossing lines.