wntr.gis.geospatial module

The wntr.gis.geospatial module contains functions to snap data and find intersects with polygons.

wntr.gis.geospatial.snap(A, B, tolerance)[source]

Snap Points in A to Points or Lines in B

For each Point geometry in A, the function returns snapped Point geometry and associated element in B. Note the CRS of A must equal the CRS of B.

Parameters
  • A (geopandas GeoDataFrame) – GeoDataFrame containing Point geometries.

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

  • tolerance (float) – Maximum allowable distance (in the coordinate reference system units) between Points in A and Points or Lines in B.

Returns

GeoPandas GeoDataFrame – Snapped points (index = A.index, columns = defined below)

If B contains Points, columns include:
  • node: closest Point in B to Point in A

  • snap_distance: distance between Point in A and snapped point

  • geometry: GeoPandas Point object of the snapped point

If B contains Lines or MultiLineString, columns include:
  • link: closest Line in B to Point in A

  • node: start or end node of Line in B that is closest to the snapped point (if B contains columns “start_node_name” and “end_node_name”)

  • snap_distance: distance between Point A and snapped point

  • line_position: normalized distance of snapped point along Line in B from the start node (0.0) and end node (1.0)

  • geometry: GeoPandas Point object of the snapped point

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 (DataFrame) – 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