| 100 | {{{!#sql |
| 101 | /*----------------------------------------- |
| 102 | Function to get all segments downstream from one one in the same subbasin |
| 103 | Problem when the subbasin changes it is difficult to go downstream |
| 104 | -----------------------------------------*/ |
| 105 | CREATE OR REPLACE FUNCTION downstream_segments(_id text) |
| 106 | RETURNS TABLE(pfafcuen character varying(254), lngtramo_m numeric) AS |
| 107 | $$ |
| 108 | BEGIN |
| 109 | RAISE NOTICE 'downstream segment for %', _id; -- prints the selected segment |
| 110 | RETURN QUERY |
| 111 | SELECT r.pfafcuen, r.lngtramo_m from oria_a_rios_v2 r |
| 112 | WHERE |
| 113 | substring(_id::text,1,char_length(_id::text)-1)= |
| 114 | substring(r.pfafcuen::text,1,char_length(r.pfafcuen::text)-1) |
| 115 | AND |
| 116 | _id>r.pfafcuen |
| 117 | AND |
| 118 | (r.pfafcuen::numeric % 2) = 1 |
| 119 | order by r.pfafcuen::numeric DESC; -- even number |
| 120 | END |
| 121 | $$ |
| 122 | LANGUAGE plpgsql VOLATILE; |
| 123 | select * from downstream_segments('10037146457'); |
| 124 | }}} |
| 126 | this query returns the three odd nodes dowstream from '10037146457' |
| 127 | |
| 128 | ||pfafcuen|| pfafrio|| |
| 129 | ||10037146451||100371464|| |
| 130 | ||10037146453||100371464|| |
| 131 | ||10037146455||100371464|| |
| 132 | Problem from that step we need to go to another number |
| 133 | |
| 134 | 10037146451 => 1003714643 |
| 135 | |
| 136 | Before trying too much the following problem arises |
| 137 | [[Image(source:eda/data/Docs/trac/sudoang/network_topology.PNG,400px)]] |