intersect#

module wntr.gis.geospatial

intersect(A, B, B_value=None, include_background=False, background_value=0)[source]#

Intersect Points, Lines or Polygons in A with Points, Lines, or Polygons in B. Return statistics on the intersection.

The function returns information about the intersection for each geometry in A. Each geometry in B is assigned a value based on a column of data in that GeoDataFrame. Note the CRS of A must equal the CRS of B.

Parameters:
  • A (geopandas GeoDataFrame) – GeoDataFrame containing Point, LineString, or Polygon geometries

  • B (geopandas GeoDataFrame) – GeoDataFrame containing Point, LineString, or Polygon geometries

  • B_value (str or None (optional)) – Column name in B used to assign a value to each geometry. Default is None.

  • include_background (bool (optional)) – Include background, defined as space covered by A that is not covered by B (overlay difference between A and B). The background geometry is added to B and is given the name ‘BACKGROUND’. Default is False.

  • background_value (int or float (optional)) – The value given to background space. This value is used in the intersection statistics if a B_value column name is provided. Default is 0.

Returns:

intersects – Intersection statistics (index = A.index, columns = defined below)

Columns include:
  • n: number of intersecting B geometries

  • intersections: list of intersecting B indices

If B_value is given:
  • values: list of intersecting B values

  • sum: sum of the intersecting B values

  • min: minimum of the intersecting B values

  • max: maximum of the intersecting B values

  • mean: mean of the intersecting B values

If A contains Lines and B contains Polygons:
  • weighted_mean: weighted mean of intersecting B values

Return type:

DataFrame