st_length.sql 1.1 KB

12345678910111213141516171819202122
  1. -- A local ecologist studying the migratory patterns of the salmon
  2. -- population in the county's waterways wants the length of all
  3. -- stream and river systems within the county.
  4. -- The waterways table is created with the ID and name columns
  5. -- which identify each stream and river system stored in the table.
  6. -- The water column is a multilinestring because the river and
  7. -- stream systems are often an aggregate of several linestrings.
  8. CREATE TABLE waterways (id integer,
  9. name varchar(128),
  10. water ST_MultiLineString);
  11. INSERT INTO waterways VALUES(
  12. 829, 'Fedders creek',
  13. ST_MLineFromText('multilinestring ((5000 0,2000 12000,17000 6000,8000 19000,21000 11000,23000 13000,25000 16000,29000 19000,31000 21000,39000 27000,45000 31000, 51000 31000, 59000 29000, 66000 29000, 75000 32000),(29000 19000,32500 26000,34000 31000,35000 39000,36000 41000,39000 48000,42000 51000,49000 58000,51000 59000,57000 62000))',1000)
  14. );
  15. -- The query returns the name of each system along with the length of
  16. -- the system generated by the ST_Length function.
  17. SELECT name, ST_Length(water) Length
  18. FROM waterways;