st_union.sql 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. -- For a special report, the county supervisor must determine the area
  2. -- of sensitive areas and five-mile hazardous site radii that aren't
  3. -- intersected.
  4. -- The sensitive_areas table contains several columns that describe the
  5. -- threatened institutions in addition to the zone column, which stores
  6. -- the institutions' ST_Polygon geometries.
  7. CREATE TABLE sensitive_areas (id integer,
  8. name varchar(128),
  9. size float,
  10. type varchar(10),
  11. zone ST_Polygon);
  12. INSERT INTO sensitive_areas VALUES(
  13. 1, 'Johnson County Hospital', 102281.91, 'hospital',
  14. ST_PolyFromText('polygon ((22000 45000,22000 58000,28000 58000,28000 42000,25000 42000,25000 45000,22000 45000))',1000)
  15. );
  16. INSERT INTO sensitive_areas VALUES(
  17. 2, 'Rydale Nursing Home', 53926.54, 'nursing hm',
  18. ST_PolyFromText('polygon ((22000 18000,28000 18000,28000 12000,22000 12000,22000 18000))',1000)
  19. );
  20. INSERT INTO sensitive_areas VALUES(
  21. 3, 'Summerhill Elementary School', 67920.64, 'school',
  22. ST_PolyFromText('polygon ((42000 18000,48000 18000,48000 13000,42000 13000,42000 18000))',1000)
  23. );
  24. -- The hazardous_sites table stores the identity of the sites in the
  25. -- site_id and name columns, while the actual geographic location of
  26. -- each site is stored in the location point column.
  27. CREATE TABLE hazardous_sites (site_id integer,
  28. name varchar(128),
  29. location ST_Point);
  30. INSERT INTO hazardous_sites VALUES(
  31. 102,
  32. 'W. H. Kleenare Chemical Repository',
  33. ST_PointFromText('point (7000 47000)',1000)
  34. );
  35. INSERT INTO hazardous_sites VALUES(
  36. 59,
  37. 'Landmark Industrial',
  38. ST_PointFromText('point (48000 39000)',1000)
  39. );
  40. -- The ST_Buffer function generates a five-mile buffer surrounding the
  41. -- hazardous waste site locations. The ST_Union function generates polygons
  42. -- from the union of the buffered hazardous waste site polygons and the
  43. -- sensitive areas. The ST_Area function returns the unioned polygon's area.
  44. SELECT sa.name sensitive_area, hs.name hazardous_site,
  45. ST_Area(ST_Union(ST_Buffer(hs.location,(5 * 5280)),sa.zone)::ST_MultiPolygon) area
  46. FROM hazardous_sites hs, sensitive_areas sa;