swn.SurfaceWaterNetwork.route_segnums#

SurfaceWaterNetwork.route_segnums(start, end, *, allow_indirect=False)#

Return a list of segnums that connect a pair of segnums.

Parameters:
start, endany

Start and end segnums.

allow_indirectbool, default False

If True, allow the route to go downstream from start to a confluence, then route upstream to end. Defalut False allows only a a direct route along a single direction up or down.

Returns:
list
Raises:
IndexError

If start and/or end segnums are not valid.

ConnecionError

If start and end segnums do not connect.

See also

gather_segnums

Query multiple segnums up and downstream.

Examples

>>> import swn
>>> 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)
>>> n.route_segnums(101, 116)
[101, 102, 106, 108, 116]
>>> n.route_segnums(101, 111)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ConnectionError: 101 does not connect to 111
>>> n.route_segnums(101, 111, allow_indirect=True)
[101, 102, 106, 108, 109, 111]