Subdomain Posts
Progress | 1 day ago
None | 5 days ago
Java | 10 days ago
REBOL | 10 days ago
Perl | 11 days ago
MySQL | 695 days ago
MySQL | 705 days ago
SQL | 735 days ago
SQL | 735 days ago
SQL | 735 days ago
Recent Posts
None | 2 sec ago
None | 9 sec ago
C | 9 sec ago
None | 15 sec ago
C++ | 16 sec ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
By Yancho on the 6th of Dec 2007 11:32:21 AM
Download |
Raw |
Embed |
Report
CREATE OR REPLACE FUNCTION near_hospital(text, integer, integer)
RETURNS integer AS
$BODY$
DECLARE
pojnt ALIAS FOR $1;
box ALIAS FOR $2;
dist ALIAS FOR $3;
distances RECORD;
nearest RECORD;
BEGIN
nearest.dist := 1000000000;
FOR distances IN
SELECT astext(h.the_geom) AS hospital_location FROM hospitals h WHERE
(
h.the_geom && expand (pointfromtext(pojnt),100000) AND
distance ( h.the_geom , pointfromtext(pojnt) ) < 150000
)
ORDER BY distance (h.the_geom , pointfromtext(pojnt)) ASC
LIMIT 3;
LOOP
SELECT INTO hospital gid, the_geom, length(the_geom) AS dist FROM shootingstar_sp
( 'streets',
(
SELECT s.gid FROM streets s, hospitals h WHERE
source = (
SELECT give_source(distances.hospital_location,100000,150000))
LIMIT 1
)
,
(
SELECT gid FROM streets WHERE
target = (SELECT give_target(pojnt,100000,150000))
LIMIT 1
)
,
5000,
'length',
true,
true
);
IF hospital.dist < nearest.dist THEN
nearest.dist := hospital.dist;
nearest.gid := hospital.gid;
SELECT INTO nearest name FROM hospital h
WHERE h.gid = hospital.gid ;
END IF;
END LOOP;
RETURN nearest.gid;
END;
' language 'plpgsql';
Submit a correction or amendment below.
[ previous version ] | [ difference ] | Make A New Post