geost.models.model_array.ModelDataArray.select_along_lines#

ModelDataArray.select_along_lines(lines: str | Path | gpd.GeoDataFrame | GeometryType, crs: str | int | CRS | None = None, distance: float | int = None, start_at_zero: bool = True, drop: bool = True) → xr.Dataset | xr.DataArray#

Select model data at specified distances along given line geometries. The lines can be provided as a GeoDataFrame, a shapely geometry, or a path to a file that can be read into a GeoDataFrame. The lines must have a valid coordinate reference system (CRS) that matches the model’s CRS, or the user can specify the CRS of the lines using the crs parameter.

Parameters:
  • lines (str | Path | gpd.GeoDataFrame | GeometryType) – Lines to select along.

  • crs (str | int | CRS | None, optional) – Coordinate reference system of the lines. If None, the CRS of the lines is assumed to be the same as the model. The default is None.

  • distance (float | int, optional) – Distance between points along the lines in meters. If None, the distance is set to the model’s x-resolution in meters. The distance will be used to compute the evenly spaced sampling points along each line. For each line, the model is sampled at the computed sampling points. The default is None.

  • start_at_zero (bool, optional) – If True, the first point along each line is at distance 0. If False, the first point is at half the distance. The default is True.

  • drop (bool, optional) – If True, anything that falls outside the model extent is dropped. So complete lines outside the extent can be dropped or the parts of the lines outside the extent can be dropped. The default is True.

Returns:

Subset of the original Dataset or DataArray with coordinates “line” and “distance” corresponding to the selected lines and distances along the lines.

Return type:

xr.Dataset | xr.DataArray

Example

Use a GeoDataFrame with lines to select the model at the x,y-locations along the lines:

>>> import geopandas as gpd
>>> lines = gpd.GeoDataFrame(
...     geometry=[
...         shapely.LineString([(0.8, 0.9), (2.4, 2.5)]),
...         shapely.LineString([(1.0, 0.5), (2.0, 1.5)]),
...     ],
...     crs="EPSG:28992"
... )
>>> model.gst.select_along_lines(lines, distance=0.2) # Select the model along the lines at 0.2m intervals

If the points are in a different CRS than the model, specify the CRS of the points:

>>> lines_wgs = lines.to_crs(4326) # Change the CRS of the lines to WGS84
>>> model.gst.select_along_lines(lines_wgs, crs=4326) # Specify the CRS of the lines