Extract topological information from netgeom column
Arguments
- x
An sf data.frame found in an
SSN
object or the netgeom column as a vector- netvars
Network coordinate variables to return. Default is "all". For edges, valid column names include: "NetworkID", "SegmentID", and "DistanceUpstream". For point datasets, valid column names include "NetworkID", "SegmentID", "DistanceUpstream", "ratio", "pid", and "locID".
- reformat
Convert network coordinate variables from character to numeric.
Value
If more than one column is requested using netvars, the function returns a data.frame (default). If only one column is requested, the result is a vector.
Details
When an SSN
object is generated using the
importSSN
function, a text column named "netgeom" is added
to the edges, observed sites, and prediction sites (if they
exist) data.frames. The netgeom column contains data used to
describe how edge and site features relate to one another in
topological space. For edges, netgeom values contain the
"ENETWORK" prefix, with 3 space delimited values in parentheses:
"ENETWORK (NetworkID SegmentID DistanceUpstream)". For point
datasets (observed and prediction sites), the values contain the
"SNETWORK" prefix, followed by 6 space delimited values in parentheses:
"SNETWORK (NetworkID SegmentID DistanceUpstream ratio pid locID)". The
ssn_get_netgeom
function extracts and converts these
values from text to numeric, returning either a data.frame
(default) or vector containing the variables requested via
netvars
.
Examples
# Copy the mf04p .ssn data to a local directory and read it into R
# When modeling with your .ssn object, you will load it using the relevant
# path to the .ssn data on your machine
copy_lsn_to_temp()
temp_path <- paste0(tempdir(), "/MiddleFork04.ssn")
mf04p <- ssn_import(temp_path, overwrite = TRUE)
ssn_get_netgeom(mf04p$obs)
#> NetworkID SegmentID DistanceUpstream ratio pid locID
#> 1 2 32 3194.82758834 0.321185040918 1 1
#> 2 2 33 3896.10674037 0.0690361937938 2 2
#> 3 2 33 4857.50889816 0.370693074276 3 3
#> 4 2 33 5886.68489225 0.693615191033 4 4
#> 5 2 33 6281.22686216 0.81740969149 5 5
#> 6 2 35 7300.18896771 0.472020290969 6 6
#> 7 2 36 8386.87883527 0.467609736278 7 7
#> 8 2 36 8626.98482356 0.595431065021 8 8
#> 9 2 38 10019.9727397 0.481795562545 9 9
#> 10 2 41 4049.94559903 0.241892607278 10 10
#> 11 2 47 8914.29845837 0.356571475119 11 11
#> 12 2 48 9295.3266467 0.223896901083 12 12
#> 13 2 51 12659.9947331 0.171145194729 13 13
#> 14 2 51 14103.2031154 0.799102017173 14 14
#> 15 2 52 16019.2025746 0.601882501114 15 15
#> 16 2 54 18447.5789988 0.132889204232 16 16
#> 17 2 57 3405.72135314 0.609185232313 17 17
#> 18 2 57 4046.04417336 0.973908806041 18 18
#> 19 2 59 5365.42224132 0.845110196768 19 19
#> 20 2 60 6489.59766227 0.885802604708 20 20
#> 21 2 60 5794.51481162 0.258397975972 21 21
#> 22 2 62 7547.78605505 0.128723349502 22 22
#> 23 2 63 10022.9334715 0.70355047499 23 23
#> 24 2 65 10879.708177 0.078434677104 24 24
#> 25 2 66 11985.9719107 0.0893958570497 25 25
#> 26 2 66 12357.0088971 0.242744463686 26 26
#> 27 2 67 15080.7113189 0.665890884643 27 27
#> 28 2 70 9921.48731634 0.881800162966 28 28
#> 29 2 94 10871.508857 0.196749884783 29 29
#> 30 2 109 11795.0008893 0.0160819902947 30 30
#> 31 1 0 16786.5620802 0.79067935202 31 31
#> 32 1 0 14295.1963452 0.0143033570212 32 32
#> 33 1 0 16258.1596546 0.626015066404 33 33
#> 34 1 4 909.868496941 0.231794110614 34 34
#> 35 1 4 1692.25764135 0.515501826192 35 35
#> 36 1 9 8046.69965981 0.280932180239 36 36
#> 37 1 12 10443.8838685 0.613552417712 37 37
#> 38 1 14 13865.3815622 0.907439930469 38 38
#> 39 1 16 14323.7279441 0.182376231574 39 39
#> 40 1 16 14580.785008 0.812239349337 40 40
#> 41 1 18 15652.4273972 0.54977020396 41 41
#> 42 1 20 18642.8233007 0.157200906378 42 42
#> 43 1 20 19566.2045371 0.639335640746 43 43
#> 44 2 48 9711.54632884 0.751115282016 44 44
#> 45 2 68 15672.8306471 0.0751878474962 45 45
ssn_get_netgeom(mf04p$edges, "DistanceUpstream")
#> DistanceUpstream
#> 1 17458.2653443
#> 2 18357.2013474
#> 3 20793.1520844
#> 4 270.643033817
#> 5 3028.37256124
#> 6 4402.46334121
#> 7 5256.1104882
#> 8 6616.51936215
#> 9 7886.30445018
#> 10 8457.24370497
#> 11 9024.57776818
#> 12 9536.51353251
#> 13 11015.393429
#> 14 12325.976268
#> 15 14022.4029322
#> 16 14249.2973301
#> 17 14657.4130884
#> 18 14790.6182827
#> 19 16358.1988978
#> 20 18341.7531704
#> 21 20256.946519
#> 22 8056.91207735
#> 23 9607.96481233
#> 24 13105.9441562
#> 25 14112.2130889
#> 26 16613.9926597
#> 27 5611.09385126
#> 28 7959.14006425
#> 29 1556.81337221
#> 30 1920.27673835
#> 31 2336.21218485
#> 32 2967.11873356
#> 33 3676.08342921
#> 34 6863.15529791
#> 35 7113.95880148
#> 36 7508.49727746
#> 37 9386.94738161
#> 38 9805.94712673
#> 39 10250.1720836
#> 40 10289.8733396
#> 41 13963.1651297
#> 42 5221.6543089
#> 43 5793.50030353
#> 44 6280.45578932
#> 45 7277.66171417
#> 46 7449.52533783
#> 47 8801.09743647
#> 48 9118.56820965
#> 49 9908.03173594
#> 50 11074.7483485
#> 51 12266.6584864
#> 52 14564.9190207
#> 53 16981.1440334
#> 54 17918.0916672
#> 55 21902.5186538
#> 56 25336.584133
#> 57 26164.3010726
#> 58 4091.85088316
#> 59 4586.16095742
#> 60 5508.24341114
#> 61 6616.11354599
#> 62 7197.21170564
#> 63 9920.68301648
#> 64 10066.0179407
#> 65 10803.9630453
#> 66 11769.6727859
#> 67 14189.23821
#> 68 15528.0057611
#> 69 17454.1798817
#> 70 20006.2582619
#> 71 10029.1136375
#> 72 10892.8779616
#> 73 11270.8487206
#> 74 11844.1591731
#> 75 13763.1476372
#> 76 12715.7735595
#> 77 14546.8345236
#> 78 17838.6435898
#> 79 8887.67517889
#> 80 8891.97355539
#> 81 12839.2250328
#> 82 5433.90934003
#> 83 6124.91189817
#> 84 6267.876827
#> 85 6677.35714099
#> 86 8073.26914058
#> 87 11585.4944924
#> 88 12057.2455603
#> 89 13058.816991
#> 90 19026.619806
#> 91 18924.7499077
#> 92 19525.005383
#> 93 19880.9175089
#> 94 21486.7688274
#> 95 13246.0911694
#> 96 14399.5534169
#> 97 10396.7058431
#> 98 12938.8411906
#> 99 17726.9196396
#> 100 15870.5572204
#> 101 20989.122938
#> 102 15125.2684793
#> 103 15389.8725133
#> 104 14793.2194916
#> 105 14808.0000677
#> 106 18347.8931324
#> 107 19583.0855759
#> 108 14729.3812838
#> 109 6772.63827193
#> 110 13344.6086556
#> 111 12092.1446817
#> 112 9641.3496983
#> 113 7320.38318899
#> 114 12444.8239212
#> 115 8982.07724987
#> 116 10769.2396836
#> 117 8257.25110283
#> 118 14762.170523
#> 119 24929.505597
#> 120 13100.4871773
#> 121 19498.8928168
#> 122 7406.49129826
#> 123 17122.0987313
#> 124 6939.68851959
#> 125 7564.94695587
#> 126 10026.1216248
#> 127 7873.39351219
#> 128 13530.4857972
#> 129 20684.2844081
#> 130 3786.82459871
#> 131 4527.88648086
#> 132 18932.7126208
#> 133 8241.4743325
#> 134 9033.46264257
#> 135 5684.90317016
#> 136 9288.41653484
#> 137 14064.8357297
#> 138 13639.3482775
#> 139 9878.97609863
#> 140 6900.36121897
#> 141 6948.21909422
#> 142 9589.88284429
#> 143 14957.8325229
#> 144 8207.03249122
#> 145 12218.7636229
#> 146 14966.125674
#> 147 10353.6917539
#> 148 10436.3448079
#> 149 16900.7317618
#> 150 11569.3278539
#> 151 13332.8551099
#> 152 11680.4722376
#> 153 12568.0861313
#> 154 13081.1159537
#> 155 12724.5995839
#> 156 17091.6681516
#> 157 15598.4603055
#> 158 14400.3070942
#> 159 15886.9084559
#> 160 10139.4205086
#> 161 7406.60614164
#> 162 6346.02608977
#> 163 7466.07885572