Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT name, gid
- FROM geonames
- ORDER BY geom <-> st_setsrid(st_makepoint(-90,40),4326)
- LIMIT 10;
- ST_Distance(geom::geography, ST_GeogFromText(''))
- --Find the nearest hospital to each school
- --that is within 3000 units of the school.
- -- We do an ST_DWithin search to utilize indexes to limit our search list
- -- that the non-indexable ST_Distance needs to process
- --If the units of the spatial reference is meters then units would be meters
- SELECT DISTINCT ON (s.gid) s.gid, s.school_name, s.the_geom, h.hospital_name
- FROM schools s
- LEFT JOIN hospitals h ON ST_DWithin(s.the_geom, h.the_geom, 3000)
- ORDER BY s.gid, ST_Distance(s.the_geom, h.the_geom);
- --The schools with no close hospitals
- --Find all schools with no hospital within 3000 units
- --away from the school. Units is in units of spatial ref (e.g. meters, feet, degrees)
- SELECT s.gid, s.school_name
- FROM schools s
- LEFT JOIN hospitals h ON ST_DWithin(s.the_geom, h.the_geom, 3000)
- WHERE h.gid IS NULL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement