swn.spatial.find_location_pairs#

swn.spatial.find_location_pairs(loc_df, n, *, all_pairs=False, exclude_branches=False)#

Find pairs of locations in a surface water network that are connected.

Parameters:
loc_dfgeopandas.GeoDataFrame or pandas.DataFrame

Location [geo] dataframe, usually created by SurfaceWaterNetwork.locate_geoms().

nSurfaceWaterNetwork

A surface water network to evaluate.

all_pairsbool, default False

If True, find all combination pairs, including those that overlap. Default False will find shortest pair combinations only.

exclude_branchesbool, default False

If True, only pairs without branches between are permitted.

Returns:
set

tuple of location index (upstream, downstream).

See also

location_pair_geoms

Extract linestring geometry for location pairs.

Examples

>>> import swn
>>> import geopandas
>>> from shapely import wkt
>>> lines = geopandas.GeoSeries(list(wkt.loads('''\
... MULTILINESTRING(
...     (380 490, 370 420), (300 460, 370 420), (370 420, 420 330),
...     (190 250, 280 270), (225 180, 280 270), (280 270, 420 330),
...     (420 330, 584 250), (520 220, 584 250), (584 250, 710 160),
...     (740 270, 710 160), (735 350, 740 270), (880 320, 740 270),
...     (925 370, 880 320), (974 300, 880 320), (760 460, 735 350),
...     (650 430, 735 350), (710 160, 770 100), (700  90, 770 100),
...     (770 100, 820  40))''').geoms))
>>> lines.index += 100
>>> n = swn.SurfaceWaterNetwork.from_lines(lines)
>>> obs_gs = geopandas.GeoSeries.from_wkt([
...    "POINT (370 400)",
...    "POINT (720 230)",
...    "POINT (780 70)",
...    "POINT (606 256)",
...    "POINT (690 170)"])
>>> obs_gs.index += 11
>>> obs_match = n.locate_geoms(obs_gs)
>>> obs_match[["segnum", "seg_ndist"]]
    segnum  seg_ndist
11     102   0.169811
12     109   0.384615
13     118   0.377049
14     108   0.093093
15     108   0.857357
>>> sorted(swn.spatial.find_location_pairs(obs_match, n))
[(11, 14), (12, 13), (14, 15), (15, 13)]
>>> sorted(swn.spatial.find_location_pairs(obs_match, n, all_pairs=True))
[(11, 13), (11, 14), (11, 15), (12, 13), (14, 13), (14, 15), (15, 13)]
>>> swn.spatial.find_location_pairs(obs_match, n, exclude_branches=True)
{(14, 15)}