Changes between Version 43 and Version 44 of CCM2 download and load


Ignore:
Timestamp:
Apr 3, 2010 10:04:02 PM (15 years ago)
Author:
cedric
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CCM2 download and load

    v43 v44  
    200200http://www.postgresql.org/docs/8.4/static/plpgsql.html 
    201201 
    202 === Plsql function which returns the id of the primary catchments within the catchment corresponding to the strahler order === 
     202=== plpgsql function which returns the id of the primary catchments within the catchment corresponding to the strahler order === 
    203203{{{ 
    204204-- it is necessary to create a type to hold the output type 
     
    360360}}} 
    361361{{{ 
    362 --examples for use 
     362--examples of use 
    363363 
    364364SELECT  ccm21.pricatch_from_catch(234706); --la vilaine dans son ensemble 
     
    370370SELECT * from ccm21.catchments where wso1_id in (SELECT  ccm21.pricatch_from_catch(234706)); 
    371371}}} 
    372  
     372=== Plgsql function which returns the riversegments upstream from the riversegment selected === 
     373{{{ 
     374DROP TYPE IF EXISTS gid; 
     375CREATE TYPE gid as (gid int); 
     376DROP  FUNCTION IF EXISTS ccm21.upstream_segments(gid_ numeric); 
     377CREATE OR REPLACE FUNCTION ccm21.upstream_segments(gid_ numeric) RETURNS setof int AS $$ 
     378        DECLARE 
     379        gid_riversegments gid%rowtype; 
     380        rec_pfafstette_length RECORD; 
     381        pfafstette_chain_length int; 
     382        pfafstette_value int8; 
     383        BEGIN 
     384        -- Valeur de la chaine pfafstette 
     385        select into pfafstette_value CAST(round(pfafstette) AS int8) FROM ccm21.riversegments where gid=gid_; 
     386        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.pricatch_from_catch(gid_)) 
     395                and CAST( 
     396                        substring(CAST(round(pfafstette) AS TEXT),1,pfafstette_chain_length) 
     397                as numeric)> pfafstette_value loop 
     398                gid_riversegments.gid=CAST(gid_riversegments.gid AS int8); 
     399                return next gid_riversegments.gid; 
     400                end loop; 
     401                return;  
     402        END; 
     403$$ 
     404LANGUAGE 'plpgsql' ; 
     405COMMENT ON FUNCTION ccm21.upstream_segments(gid_ numeric) IS 'This function uses ccm21.pricatch_from_catch to get all the segments from a catchment and searches all segments with a pfafstetter higher than the segment in the bassin. The pfafstette are trucated to the level of the segment used as input in the function'; 
     406}}} 
     407Usage example 
     408{{{ 
     409select ccm21.upstream_segments(234706); 
     410}}}