pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

yancho private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Yancho on Sat 26 Jan 11:06 (modification of post by Yancho view diff)
report abuse | download | new post

  1. -- Function: near_accident(text, text)
  2.  
  3. -- DROP FUNCTION near_accident(text, text);
  4.  
  5. CREATE OR REPLACE FUNCTION near_accident(text, text)
  6.   RETURNS text AS
  7. $BODY$
  8.  
  9.         DECLARE
  10.                 pojnt ALIAS FOR $1;
  11.                 tejbil ALIAS FOR $2;
  12.                 distances RECORD;
  13.                 hospital RECORD;
  14.                 nearest RECORD;
  15.                 silect TEXT;
  16.                
  17.                 sorc INTEGER;
  18.                 targit INTEGER;
  19.  
  20.         BEGIN
  21.                
  22.                 SELECT 'inf'::float8 AS dist, NULL::text AS gid INTO nearest;
  23.          
  24. raise notice 'Point is %', pojnt;    
  25. SELECT give_target(pojnt,1000,200) INTO targit;
  26. raise notice 'value of target : %',targit;
  27.  
  28. raise notice '-----------------------------------------------';
  29.         ) ;
  30.  
  31.         silect := ' select astext(h.the_geom) as hospital_location from '|| tejbil ||' h where
  32.                                          (
  33.                                          h.the_geom && expand (pointfromtext('|| quote_literal(pojnt) ||'),100000) and
  34.                                          distance ( h.the_geom , pointfromtext('|| quote_literal(pojnt) ||') ) < 150000
  35.                                          )
  36.                                     order by distance (h.the_geom , pointfromtext('|| quote_literal(pojnt) ||')) ASC
  37.                                     limit 3 ';
  38.        
  39.  
  40.                FOR distances IN
  41.                                         EXECUTE silect
  42.  
  43.  
  44.                
  45.                 LOOP
  46.  
  47. raise notice '=====================================================';   
  48.  raise notice 'point location of hospital : %', distances.hospital_location;   
  49.  
  50.  
  51.  
  52.  
  53. SELECT give_source(distances.hospital_location,1000,200) INTO sorc;
  54. raise notice 'value of sorc : %', sorc;
  55.  
  56.                 SELECT gid, the_geom, length(the_geom) AS dist INTO hospital FROM shootingstar_sp
  57.                               ( 'streets',
  58.                                    
  59.                                     (
  60.                                         SELECT s.gid FROM streets s WHERE
  61.                                         source = (sorc)
  62.                                         LIMIT 1
  63.  
  64.  
  65.                                     )
  66.  
  67.                                     ,
  68.  
  69.                                     (
  70.                                         SELECT gid FROM streets WHERE
  71.                                         target = ( targit)
  72.                                         LIMIT 1
  73.  
  74.                                     )
  75.                                    
  76.                                     ,
  77.                                    5000,
  78.                                    'rcost',
  79.                                    true,
  80.                                    true
  81.                               );
  82.          
  83.           raise notice 'Hospital Distance %', hospital.dist ;            
  84.  
  85.                       IF hospital.dist < nearest.dist  THEN
  86.                           nearest.dist := hospital.dist;
  87.          raise notice 'value of nearest.dist is %', nearest.dist;
  88.          raise notice 'value of hospital.gid is %', hospital.gid;
  89.         raise notice 'value of nearest.gid is %', nearest.gid;
  90.                           nearest.gid := distances.hospital_location;
  91.         raise notice 'value of 2ND nearest.gid is %', nearest.gid;
  92.  
  93.                       END IF;
  94.  
  95.                      
  96.                END LOOP;
  97.    
  98.                RETURN nearest.gid;
  99.              
  100.         END;
  101.         $BODY$
  102.   LANGUAGE 'plpgsql' VOLATILE;
  103. ALTER FUNCTION near_accident(text, text) OWNER TO yancho;

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post