Quickstart guide#

The aim of this guide is to provide a quick overview of the capabilities of this package to read GIS inputs to create a surface water network.

Surface water network#

This example is based on this image that illustrates Strahler number.

In [1]: import swn

In [2]: import geopandas

In [3]: from shapely import wkt

In [4]: 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))
   ...: 

In [5]: lines.index += 100

In [6]: lines.index.name = "idx"

Create a surface water network object from the lines using SurfaceWaterNetwork.from_lines(), then illustrate a few properties:

In [7]: n = swn.SurfaceWaterNetwork.from_lines(lines)

In [8]: print(n)
<SurfaceWaterNetwork:
  19 segments: [100, 101, ..., 117, 118]
  10 headwater: [100, 101, ..., 115, 117]
  1 outlets: [118]
  no diversions />

In [9]: print(n.segments[["to_segnum", "from_segnums", "stream_order", "num_to_outlet"]])
     to_segnum from_segnums  stream_order  num_to_outlet
idx                                                     
100        102           {}             1              6
101        102           {}             1              6
102        106   {100, 101}             2              5
103        105           {}             1              6
104        105           {}             1              6
105        106   {104, 103}             2              5
106        108   {105, 102}             3              4
107        108           {}             1              4
108        116   {106, 107}             3              3
109        116   {110, 111}             3              3
110        109   {114, 115}             2              4
111        109   {112, 113}             2              4
112        111           {}             1              5
113        111           {}             1              5
114        110           {}             1              5
115        110           {}             1              5
116        118   {108, 109}             4              2
117        118           {}             1              2
118          0   {116, 117}             4              1

In [10]: n.plot();
savefig/fluss_swn.png