Network queries

veneer-py supports a number topological queries on the Source node-link network and including identifying outlets, upstream and downstream nodes, links and catchments.

These queries operate on the network object returned by v.network(). The topological queriers are not available on the dataframe version (created with .as_dataframe()), although in some cases the results of the previous queries can be carried over to the dataframe.


In [1]:
import veneer
%matplotlib inline

In [2]:
v = veneer.Veneer()

In [3]:

Different forms of the network.

The node-link network that we get from Source includes topological information, in addition to the geometries of the various nodes, links and catchments, and their attributes, such as node names.

When we initial retrieve the network, with v.network() we get an object that includes a number of queries based on this topology.

Note: These queries are not implemented on the dataframe of the network, created with v.network().as_dataframe(). However you can call as_dataframe() on the result of some of the topological queries.


In [4]:
network = v.network()

eg, find all outlet nodes


In [5]:
outlets = network.outlet_nodes().as_dataframe()
outlets[:10]


Out[5]:
feature_type geometry icon name id
0 node POINT (350180 5768600) /resources/ConfluenceNodeModel Outlet Node1 /network/nodes/187
1 node POINT (358140 5769280) /resources/ConfluenceNodeModel Outlet Node2 /network/nodes/198
2 node POINT (363720 5768780) /resources/ConfluenceNodeModel Toomuc Ck Outlet /network/nodes/205
3 node POINT (367740 5767240) /resources/ConfluenceNodeModel Yallock Ck Outlet /network/nodes/214
4 node POINT (347580 5768100) /resources/ConfluenceNodeModel Outlet Node5 /network/nodes/215
5 node POINT (348880 5768520) /resources/ConfluenceNodeModel Outlet Node6 /network/nodes/224
6 node POINT (366400 5767620) /resources/ConfluenceNodeModel Outlet Node7 /network/nodes/228
7 node POINT (357480 5769580) /resources/ConfluenceNodeModel Outlet Node8 /network/nodes/237
8 node POINT (363020 5769140) /resources/ConfluenceNodeModel Cardinia Ck Outlet /network/nodes/242
9 node POINT (364540 5768780) /resources/ConfluenceNodeModel Bunyip R Outlet /network/nodes/247

Feature id

Other topological queries are based on the id attribute of features in the network. For example /network/nodes/187


In [6]:
upstream_features = network.upstream_features('/network/nodes/214').as_dataframe()
upstream_features


Out[6]:
areaInSquareMeters feature_type from_node geometry icon length link name to_node id
0 NaN link /network/nodes/212 LINESTRING (373480 5771840, 367740 5767240) NaN 9195.676759 NaN link for catchment SC #203 /network/nodes/214 /network/link/199
1 8171200.0 catchment NaN (POLYGON ((374010 5773170, 374070 5773170, 374... NaN NaN /network/link/199 SC #203 NaN /network/catchments/21253
2 NaN node NaN POINT (373480 5771840) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #203 NaN /network/nodes/212
3 NaN link /network/nodes/175 LINESTRING (375140 5773220, 373480 5771840) NaN 2414.213562 NaN link for catchment SC #199 /network/nodes/212 /network/link/195
4 NaN link /network/nodes/220 LINESTRING (377680 5770860, 373480 5771840) NaN 5214.701295 NaN link for catchment SC #208 /network/nodes/212 /network/link/204
5 1570800.0 catchment NaN (POLYGON ((375210 5773530, 375250 5773530, 375... NaN NaN /network/link/195 SC #199 NaN /network/catchments/2500
6 NaN node NaN POINT (375140 5773220) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #199 NaN /network/nodes/175
7 NaN link /network/nodes/176 LINESTRING (375500 5773700, 375140 5773220) NaN 600.832611 NaN link for catchment SC #163 /network/nodes/175 /network/link/159
8 NaN link /network/nodes/191 LINESTRING (375360 5773280, 375140 5773220) NaN 224.852814 NaN link for catchment SC #200 /network/nodes/175 /network/link/196
9 5260400.0 catchment NaN (POLYGON ((380610 5777870, 380630 5777870, 380... NaN NaN /network/link/159 SC #163 NaN /network/catchments/8029
10 NaN node NaN POINT (375500 5773700) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #163 NaN /network/nodes/176
11 13600.0 catchment NaN (POLYGON ((375330 5773310, 375350 5773310, 375... NaN NaN /network/link/196 SC #200 NaN /network/catchments/21424
12 NaN node NaN POINT (375360 5773280) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #200 NaN /network/nodes/191
13 NaN link /network/nodes/186 LINESTRING (378260 5775140, 375360 5773280) NaN 5079.310242 NaN link for catchment SC #177 /network/nodes/191 /network/link/173
14 NaN link /network/nodes/208 LINESTRING (377400 5773000, 375360 5773280) NaN 2164.264069 NaN link for catchment SC #195 /network/nodes/191 /network/link/191
15 5534400.0 catchment NaN (POLYGON ((378390 5776130, 378390 5775970, 378... NaN NaN /network/link/173 SC #177 NaN /network/catchments/11164
16 NaN node NaN POINT (378260 5775140) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #177 NaN /network/nodes/186
17 NaN link /network/nodes/164 LINESTRING (380200 5776700, 378260 5775140) NaN 3049.949494 NaN link for catchment SC #170 /network/nodes/186 /network/link/166
18 NaN link /network/nodes/190 LINESTRING (382680 5774440, 378260 5775140) NaN 5539.066376 NaN link for catchment SC #176 /network/nodes/186 /network/link/172
19 5660000.0 catchment NaN (POLYGON ((380170 5776750, 380190 5776750, 380... NaN NaN /network/link/166 SC #170 NaN /network/catchments/10765
20 NaN node NaN POINT (380200 5776700) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #170 NaN /network/nodes/164
21 NaN link /network/nodes/165 LINESTRING (381500 5777100, 380200 5776700) NaN 1437.401154 NaN link for catchment SC #153 /network/nodes/164 /network/link/149
22 NaN link /network/nodes/171 LINESTRING (383960 5776140, 380200 5776700) NaN 3980.243866 NaN link for catchment SC #158 /network/nodes/164 /network/link/154
23 6389600.0 catchment NaN (POLYGON ((386450 5779550, 386470 5779550, 386... NaN NaN /network/link/149 SC #153 NaN /network/catchments/1588
24 NaN node NaN POINT (381500 5777100) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #153 NaN /network/nodes/165
25 8839600.0 catchment NaN (POLYGON ((386950 5778390, 386950 5778150, 386... NaN NaN /network/link/154 SC #158 NaN /network/catchments/1246
26 NaN node NaN POINT (383960 5776140) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #158 NaN /network/nodes/171
27 7496800.0 catchment NaN (POLYGON ((382930 5776230, 383010 5776230, 383... NaN NaN /network/link/172 SC #176 NaN /network/catchments/11107
28 NaN node NaN POINT (382680 5774440) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #176 NaN /network/nodes/190
29 NaN link /network/nodes/145 LINESTRING (386440 5773880, 382680 5774440) NaN 3988.528137 NaN link for catchment SC #178 /network/nodes/190 /network/link/174
... ... ... ... ... ... ... ... ... ... ...
72 23071200.0 catchment NaN (POLYGON ((396950 5774810, 396950 5774790, 397... NaN NaN /network/link/183 SC #187 NaN /network/catchments/961
73 NaN node NaN POINT (397040 5771480) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #187 NaN /network/nodes/200
74 5404800.0 catchment NaN (POLYGON ((392830 5770950, 392830 5770930, 392... NaN NaN /network/link/214 SC #218 NaN /network/catchments/8428
75 NaN node NaN POINT (392920 5770380) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #218 NaN /network/nodes/234
76 1478000.0 catchment NaN (POLYGON ((387210 5772450, 387230 5772450, 387... NaN NaN /network/link/205 SC #209 NaN /network/catchments/21139
77 NaN node NaN POINT (387080 5771340) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #209 NaN /network/nodes/221
78 NaN link /network/nodes/230 LINESTRING (389540 5770860, 387080 5771340) NaN 2630.538239 NaN link for catchment SC #215 /network/nodes/221 /network/link/211
79 NaN link /network/nodes/231 LINESTRING (387920 5769560, 387080 5771340) NaN 2796.812409 NaN link for catchment SC #216 /network/nodes/221 /network/link/212
80 6988400.0 catchment NaN (POLYGON ((388730 5771470, 389130 5771470, 389... NaN NaN /network/link/211 SC #215 NaN /network/catchments/8827
81 NaN node NaN POINT (389540 5770860) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #215 NaN /network/nodes/230
82 10899600.0 catchment NaN (POLYGON ((387070 5771330, 387090 5771330, 387... NaN NaN /network/link/212 SC #216 NaN /network/catchments/8770
83 NaN node NaN POINT (387920 5769560) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #216 NaN /network/nodes/231
84 8646400.0 catchment NaN (POLYGON ((382710 5774430, 382710 5774410, 382... NaN NaN /network/link/185 SC #189 NaN /network/catchments/21766
85 NaN node NaN POINT (384440 5772960) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #189 NaN /network/nodes/201
86 4002400.0 catchment NaN (POLYGON ((377430 5774030, 377610 5774030, 377... NaN NaN /network/link/191 SC #195 NaN /network/catchments/2899
87 NaN node NaN POINT (377400 5773000) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #195 NaN /network/nodes/208
88 NaN link /network/nodes/209 LINESTRING (382220 5772280, 377400 5773000) NaN 6130.782105 NaN link for catchment SC #196 /network/nodes/208 /network/link/192
89 NaN link /network/nodes/216 LINESTRING (378380 5772820, 377400 5773000) NaN 1026.274170 NaN link for catchment SC #205 /network/nodes/208 /network/link/201
90 6729200.0 catchment NaN (POLYGON ((378150 5773950, 378190 5773950, 378... NaN NaN /network/link/192 SC #196 NaN /network/catchments/2956
91 NaN node NaN POINT (382220 5772280) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #196 NaN /network/nodes/209
92 NaN link /network/nodes/213 LINESTRING (384180 5771380, 382220 5772280) NaN 2973.380951 NaN link for catchment SC #201 /network/nodes/209 /network/link/197
93 NaN link /network/nodes/222 LINESTRING (382220 5771740, 382220 5772280) NaN 573.137085 NaN link for catchment SC #210 /network/nodes/209 /network/link/206
94 7134400.0 catchment NaN (POLYGON ((382530 5773310, 382570 5773310, 382... NaN NaN /network/link/197 SC #201 NaN /network/catchments/7801
95 NaN node NaN POINT (384180 5771380) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #201 NaN /network/nodes/213
96 5450400.0 catchment NaN (POLYGON ((382250 5772270, 382250 5772250, 382... NaN NaN /network/link/206 SC #210 NaN /network/catchments/8656
97 NaN node NaN POINT (382220 5771740) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #210 NaN /network/nodes/222
98 5574400.0 catchment NaN (POLYGON ((377430 5773010, 377530 5773010, 377... NaN NaN /network/link/201 SC #205 NaN /network/catchments/21595
99 NaN node NaN POINT (378380 5772820) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #205 NaN /network/nodes/216
100 12852800.0 catchment NaN (POLYGON ((374710 5772610, 374770 5772610, 374... NaN NaN /network/link/204 SC #208 NaN /network/catchments/21196
101 NaN node NaN POINT (377680 5770860) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #208 NaN /network/nodes/220

102 rows × 10 columns


In [7]:
upstream_features.plot()


Out[7]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff4ffa70550>

Partitioning the network

The network.partition method can be very useful for a range of parameterisation and reporting needs.

partition groups all features (nodes, links and catchments) in the network based on which of a series of key nodes those features drain through.

parition adds a new property to each feature, naming the relevant key node (or the outlet node if none of the key nodes are downstream of a particular feature).

Note: You can name the property used to identify the key nodes, which means you can run partition multiple times to identify different groupings within the network


In [8]:
network.partition?


Signature: network.partition(key_features, new_prop)
Docstring:
Partition the network by a list of feature names (key_features).

Add property (new_prop) to each feature identifying next downstream feature from key_features.

Features in key_features are assigned to their own group.

Features with no downstream key_feature (eg close to outlets) are attributed with their outlet node
File:      ~/src/projects/py/veneer-py/veneer/extensions.py
Type:      method

In [9]:
gauge_names = network['features'].find_by_icon('/resources/GaugeNodeModel')._select(['name'])
gauge_names


Out[9]:
['228212_BunyipR_Tonimbuk',
 '228217_ToomucCk_PrincesHwy',
 '228228_CardiniaCk_ChasemoreRd',
 '228255_BunyipR_CannibalCk',
 '228201_TaragoR_DrouinWest',
 '228213_BunyipR_Iona',
 '227219_BassR_Loch',
 '227231_BassR_McGrathsRd',
 '228208_LangLangR_LangLang',
 '228209_LangLang_HamiltonsBrRd']

In [10]:
network.partition(gauge_names,'downstream_gauge')

In [11]:
dataframe = network.as_dataframe()
dataframe[:10]


Out[11]:
areaInSquareMeters downstream_gauge feature_type from_node geometry icon length link name to_node id
0 NaN 228212_BunyipR_Tonimbuk node NaN POINT (385780 5803320) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #003 NaN /network/nodes/0
1 NaN 228212_BunyipR_Tonimbuk node NaN POINT (384360 5804140) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #001 NaN /network/nodes/1
2 NaN 228212_BunyipR_Tonimbuk node NaN POINT (385820 5803660) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #002 NaN /network/nodes/2
3 NaN 228212_BunyipR_Tonimbuk node NaN POINT (389820 5800500) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #016 NaN /network/nodes/3
4 NaN 228201_TaragoR_DrouinWest node NaN POINT (403700 5799060) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #023 NaN /network/nodes/4
5 NaN 228201_TaragoR_DrouinWest node NaN POINT (403780 5801580) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #004 NaN /network/nodes/5
6 NaN 228201_TaragoR_DrouinWest node NaN POINT (400320 5800360) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #014 NaN /network/nodes/6
7 NaN 228201_TaragoR_DrouinWest node NaN POINT (399000 5801020) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #005 NaN /network/nodes/7
8 NaN 228212_BunyipR_Tonimbuk node NaN POINT (381760 5799480) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #021 NaN /network/nodes/8
9 NaN 228212_BunyipR_Tonimbuk node NaN POINT (382240 5800640) /resources/ConfluenceNodeModel NaN NaN Node on catchment SC #006 NaN /network/nodes/9

In [12]:
## Path between two features

In [13]:
network.path_between?


Signature: network.path_between(from_feature, to_feature)
Docstring: <no docstring>
File:      ~/src/projects/py/veneer-py/veneer/extensions.py
Type:      method

In [17]:
network.path_between('/network/catchments/20797','/network/nodes/56').as_dataframe()


Out[17]:
downstream_gauge feature_type from_node geometry icon length name to_node id
0 228212_BunyipR_Tonimbuk link /network/nodes/0 LINESTRING (385780 5803320, 389820 5800500) NaN 5840.386720 link for catchment SC #003 /network/nodes/3 /network/link/2
1 228212_BunyipR_Tonimbuk node NaN POINT (389820 5800500) /resources/ConfluenceNodeModel NaN Node on catchment SC #016 NaN /network/nodes/3
2 228212_BunyipR_Tonimbuk link /network/nodes/3 LINESTRING (389820 5800500, 388920 5796800) NaN 5351.858582 link for catchment SC #016 /network/nodes/21 /network/link/15
3 228212_BunyipR_Tonimbuk node NaN POINT (388920 5796800) /resources/ConfluenceNodeModel NaN Node on catchment SC #030 NaN /network/nodes/21
4 228212_BunyipR_Tonimbuk link /network/nodes/21 LINESTRING (388920 5796800, 390300 5795980) NaN 1934.213562 link for catchment SC #030 /network/nodes/28 /network/link/29
5 228212_BunyipR_Tonimbuk node NaN POINT (390300 5795980) /resources/ConfluenceNodeModel NaN Node on catchment SC #040 NaN /network/nodes/28
6 228212_BunyipR_Tonimbuk link /network/nodes/28 LINESTRING (390300 5795980, 390740 5795200) NaN 1130.538239 link for catchment SC #040 /network/nodes/37 /network/link/37
7 228212_BunyipR_Tonimbuk node NaN POINT (390740 5795200) /resources/ConfluenceNodeModel NaN Node on catchment SC #047 NaN /network/nodes/37
8 228212_BunyipR_Tonimbuk link /network/nodes/37 LINESTRING (390740 5795200, 391320 5793680) NaN 2024.507935 link for catchment SC #047 /network/nodes/43 /network/link/44
9 228212_BunyipR_Tonimbuk node NaN POINT (391320 5793680) /resources/ConfluenceNodeModel NaN Node on catchment SC #051 NaN /network/nodes/43
10 228212_BunyipR_Tonimbuk link /network/nodes/43 LINESTRING (391320 5793680, 391540 5791640) NaN 2555.634919 link for catchment SC #051 /network/nodes/56 /network/link/47
11 228212_BunyipR_Tonimbuk node NaN POINT (391540 5791640) /resources/GaugeNodeModel NaN 228212_BunyipR_Tonimbuk NaN /network/nodes/56

In [ ]:


In [ ]: