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 Mon 7 Jan 10:30 (modification of post by Yancho view diff)
report abuse | download | new post

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