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.

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.

  • max_snap_distance (float)

Returns:

  • uds (UgridDataset) – Snapped line geometries as edges in a Ugrid2d topology. Contains a line_index variable identifying the original geodataframe line.

  • gdf (gpd.GeoDataFrame) – Snapped line geometries.