xugrid.snap_to_grid#

xugrid.snap_to_grid(lines: GeoDataFrame, grid: DataArray | UgridDataArray, max_snap_distance: float) Tuple[ndarray, DataFrame | GeoDataFrame][source]#

Snap a collection of lines to a grid.

A line is included and snapped to a grid edge when the line separates the centroid of the cell with the centroid of the edge.

When a line in a cell is snapped to an edge that is not shared with another cell, this is denoted with a value of -1 in the second column of cell_to_cell.

Parameters:
  • lines (gpd.GeoDataFrame) – Line data. Geometry colum should contain exclusively LineStrings.

  • grid (xr.DataArray or xu.UgridDataArray of integers) – Grid of cells to snap lines to. Cells with a value of 0 are not included.

  • max_snap_distance (float) –

Returns:

  • cell_to_cell (ndarray of integers with shape (N, 2)) – Cells whose centroids are separated from each other by a line.

  • segment_data (pd.DataFrame or gpd.DataFrame) – Data for every segment. GeoDataFrame if return_geometry is True.