Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. SELECT name, gid
  2. FROM geonames
  3. ORDER BY geom <-> st_setsrid(st_makepoint(-90,40),4326)
  4. LIMIT 10;
  5.  
  6. ST_Distance(geom::geography, ST_GeogFromText(''))
  7.  
  8. --Find the nearest hospital to each school
  9. --that is within 3000 units of the school.
  10. -- We do an ST_DWithin search to utilize indexes to limit our search list
  11. -- that the non-indexable ST_Distance needs to process
  12. --If the units of the spatial reference is meters then units would be meters
  13. SELECT DISTINCT ON (s.gid) s.gid, s.school_name, s.the_geom, h.hospital_name
  14. FROM schools s
  15. LEFT JOIN hospitals h ON ST_DWithin(s.the_geom, h.the_geom, 3000)
  16. ORDER BY s.gid, ST_Distance(s.the_geom, h.the_geom);
  17.  
  18. --The schools with no close hospitals
  19. --Find all schools with no hospital within 3000 units
  20. --away from the school. Units is in units of spatial ref (e.g. meters, feet, degrees)
  21. SELECT s.gid, s.school_name
  22. FROM schools s
  23. LEFT JOIN hospitals h ON ST_DWithin(s.the_geom, h.the_geom, 3000)
  24. WHERE h.gid IS NULL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement