Posted by Yancho on Sat 26 Jan 11:06 (modification of post by Yancho view diff)
report abuse | download | new post
- -- Function: near_accident(text, text)
- -- DROP FUNCTION near_accident(text, text);
- CREATE OR REPLACE FUNCTION near_accident(text, text)
- RETURNS text AS
- $BODY$
- DECLARE
- pojnt ALIAS FOR $1;
- tejbil ALIAS FOR $2;
- distances RECORD;
- hospital RECORD;
- nearest RECORD;
- silect TEXT;
- sorc INTEGER;
- targit INTEGER;
- BEGIN
- SELECT 'inf'::float8 AS dist, NULL::text AS gid INTO nearest;
- raise notice 'Point is %', pojnt;
- SELECT give_target(pojnt,1000,200) INTO targit;
- raise notice 'value of target : %',targit;
- raise notice '-----------------------------------------------';
- ) ;
- silect := ' select astext(h.the_geom) as hospital_location from '|| tejbil ||' h where
- (
- h.the_geom && expand (pointfromtext('|| quote_literal(pojnt) ||'),100000) and
- distance ( h.the_geom , pointfromtext('|| quote_literal(pojnt) ||') ) < 150000
- )
- order by distance (h.the_geom , pointfromtext('|| quote_literal(pojnt) ||')) ASC
- limit 3 ';
- FOR distances IN
- EXECUTE silect
- LOOP
- raise notice '=====================================================';
- raise notice 'point location of hospital : %', distances.hospital_location;
- SELECT give_source(distances.hospital_location,1000,200) INTO sorc;
- raise notice 'value of sorc : %', sorc;
- SELECT gid, the_geom, length(the_geom) AS dist INTO hospital FROM shootingstar_sp
- ( 'streets',
- (
- SELECT s.gid FROM streets s WHERE
- source = (sorc)
- LIMIT 1
- )
- ,
- (
- SELECT gid FROM streets WHERE
- target = ( targit)
- LIMIT 1
- )
- ,
- 5000,
- 'rcost',
- true,
- true
- );
- raise notice 'Hospital Distance %', hospital.dist ;
- IF hospital.dist < nearest.dist THEN
- nearest.dist := hospital.dist;
- raise notice 'value of nearest.dist is %', nearest.dist;
- raise notice 'value of hospital.gid is %', hospital.gid;
- raise notice 'value of nearest.gid is %', nearest.gid;
- nearest.gid := distances.hospital_location;
- raise notice 'value of 2ND nearest.gid is %', nearest.gid;
- END IF;
- END LOOP;
- RETURN nearest.gid;
- END;
- $BODY$
- LANGUAGE 'plpgsql' VOLATILE;
- 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.