384 | | -- Valeur de la chaine pfafstette |
| 389 | -- filling a new table with the results from a catchment |
| 390 | |
| 391 | DROP TABLE IF EXISTS ccm21.upstream_riversegments; |
| 392 | CREATE TABLE ccm21.upstream_riversegments AS SELECT * FROM ccm21.riversegments |
| 393 | where wso1_id in (SELECT ccm21.mycatchment(gid_)); |
| 394 | ALTER TABLE ccm21.upstream_riversegments ADD CONSTRAINT pk_upstream_riversegments PRIMARY KEY (gid); |
| 395 | |
| 396 | -- pfafstette chain length |
| 397 | --select into pfafstette_chain_length character_length(CAST(round(pfafstette) AS TEXT) |
| 398 | -- FROM ccm21.upstream_riversegments WHERE gid=gid_; |
| 399 | -- RAISE NOTICE 'pfafstette chain length is %', pfafstette_chain_length; |
| 400 | -- pfafstette max chain length in the selected basin |
| 401 | select into pfafstette_max_chain_length max(character_length(CAST(round(pfafstette) AS TEXT))) |
| 402 | FROM ccm21.upstream_riversegments; |
| 403 | -- pfafstette value |
| 404 | -- the chain is lengthened to the pfafstette max chain length |
| 405 | Update ccm21.upstream_riversegments set pfafstette = |
| 406 | floor(pfafstette)*power(10,(pfafstette_max_chain_length-character_length(CAST(floor(pfafstette) AS TEXT) ))); |
387 | | -- Longueur de la chaine pfafstette |
388 | | select into rec_pfafstette_length character_length(CAST(round(pfafstette) AS TEXT)) AS length |
389 | | FROM ccm21.riversegments WHERE gid=gid_; |
390 | | pfafstette_chain_length=rec_pfafstette_length.length; |
391 | | RAISE NOTICE 'pfafstette chain length is %', pfafstette_chain_length; |
392 | | -- loop |
393 | | for gid_riversegments in select gid from ccm21.riversegments |
394 | | where wso1_id in (SELECT ccm21.mycatchment(gid_)) |
395 | | and CAST( |
396 | | substring(CAST(round(pfafstette) AS TEXT),1,pfafstette_chain_length) |
397 | | as numeric)>= pfafstette_value loop |
| 409 | |
| 410 | DELETE FROM ccm21.upstream_riversegments WHERE pfafstette < pfafstette_value; |
| 411 | -- extracting the riversegments corresponding to the basin |
| 412 | |
| 413 | for gid_riversegments in select gid from ccm21.upstream_riversegments order by gid loop |