Changes between Version 57 and Version 58 of CCM2 download and load


Ignore:
Timestamp:
Apr 5, 2010 6:27:14 PM (15 years ago)
Author:
cedric
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CCM2 download and load

    v57 v58  
    371371}}} 
    372372=== Plpgsql function which returns the riversegments upstream from the riversegment selected === 
     373Note : It is necessary to create a table as the pfafstetter along an axis can have a shorter length upstream than the length selected 
     374The maximum length for a pfafstetter is 14 in the ccm. Transforming the database to store a column number with 14 number would increase the size of the database. 
     375It is also not possible to create a variable in PlSql storing more than one line. For these two reasons, a table upstream_segments is created and is filled with  
    373376{{{ 
    374377DROP TYPE IF EXISTS gid; 
     
    377380CREATE OR REPLACE FUNCTION ccm21.upstream_segments(gid_ numeric) RETURNS setof int AS $$ 
    378381        DECLARE 
    379         gid_riversegments gid%rowtype; 
     382        gid_riversegments gid%ROWTYPE; 
    380383        rec_pfafstette_length RECORD; 
    381         pfafstette_chain_length int; 
     384        rec_riversegments ccm21.riversegments%ROWTYPE; 
     385        -- pfafstette_chain_length int; 
     386        pfafstette_max_chain_length int; 
    382387        pfafstette_value int8; 
    383388        BEGIN 
    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) )));   
    385407        select into pfafstette_value CAST(round(pfafstette) AS int8) FROM ccm21.riversegments where gid=gid_; 
    386408        RAISE NOTICE 'pfafstette  is %', pfafstette_value; 
    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 
    398414                gid_riversegments.gid=CAST(gid_riversegments.gid AS int8); 
    399415                return next gid_riversegments.gid;