st_buffer.sql 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. -- The County Supervisor needs a list of hazardous sites whose five-mile
  2. -- radius overlaps sensitive areas such as schools, hospitals, and nursing
  3. -- homes. The sensitive areas are stored in the table sensitive_areas that
  4. -- is created with the CREATE TABLE statement below. The zone column, defined
  5. -- as a ST_Polygon, stores the outline of each of the sensitive areas.
  6. CREATE TABLE sensitive_areas (id integer,
  7. name varchar(128),
  8. size float,
  9. type varchar(10),
  10. zone ST_Polygon);
  11. -- The hazardous sites are stored in the hazardous_sites table created below.
  12. -- The location column, defined as a point, stores the geographic center of
  13. -- each hazardous site.
  14. CREATE TABLE hazardous_sites (site_id integer,
  15. name varchar(128),
  16. location ST_Point);
  17. INSERT INTO sensitive_areas VALUES(
  18. 1, 'Johnson County Hospital', 102281.91, 'hospital',
  19. ST_PolyFromText('polygon ((22000 45000,22000 58000,28000 58000,28000 42000,25000 42000,25000 45000,22000 45000))',1000));
  20. INSERT INTO sensitive_areas VALUES(
  21. 2, 'Rydale Nursing Home', 53926.54, 'nursing hm',
  22. ST_PolyFromText('polygon ((22000 18000,28000 18000,28000 12000,22000 12000,22000 18000))',1000));
  23. INSERT INTO sensitive_areas VALUES(
  24. 3, 'Summerhill Elementary School', 67920.64, 'school',
  25. ST_PolyFromText('polygon ((42000 18000,48000 18000,48000 13000,42000 13000,42000 18000))',1000));
  26. INSERT INTO hazardous_sites VALUES(
  27. 102, 'W. H. Kleenare Chemical Repository',
  28. ST_PointFromText('point (7000 47000)',1000)
  29. );
  30. INSERT INTO hazardous_sites VALUES(
  31. 59, 'Landmark Industrial',
  32. ST_PointFromText('point (48000 39000)',1000)
  33. );
  34. -- The sensitive_areas and hazardous_sites tables are joined by the
  35. -- ST_Overlaps function, which returns t (TRUE) for all sensitive_areas
  36. -- rows whose zone polygons overlap the buffered five-mile radius of the
  37. -- hazardous_sites location point.
  38. SELECT sa.name, hs.name
  39. FROM sensitive_areas sa, hazardous_sites hs
  40. WHERE ST_Overlaps(sa.zone, ST_Buffer(hs.location,26400));