title: Finding path length along points in postgis
body: <p>I have a postgis database (postgres 8.4.11, postgis 1.5.2) with gps-observations where I would like to calculate some travel distances. </p>
  
  <p>I calculate the travelled distance from one point to another one hour later with 
  select observedid,ST_Distance(p1.shape_utm,p2.shape_utm) from gpspoint p1, gpspoint p2 where p2.datetime=p1.datetime+interval '1 hour'</p>
  
  <p>(and of course a bit more, but this is the distance part in it) I have defined this as a view so that I can easily do a 
  select * from movement_view where observedid=42</p>
  
  <p>Question 1:
  Is it possible to make the view so that I can define the time interval as well? </p>
  
  <p>e.g. select * form movement_view where observedid=42 and interval='15 minutes' ?</p>
  
  <p>Question 2:
  Is it possible in SQL/postgis to calculate the total distance travelled for a period of time? I have a gpspoint each 5th second and would like to calculate travelled distance for e.g. 1 hour following each gps-point. I can calculate the travelled distance for each point using the same method as above, and then I may be able to use the sum() function, but how?</p>
  
  <p>Table definition: 
  id integer,<br>
  gpsstatus character(2),<br>
  datetime timestamp without time zone,<br>
  lat numeric(9,6),<br>
  lon numeric(9,6),<br>
  alt numeric(9,4),<br>
  time integer,<br>
  datafileid integer,<br>
  shape geometry,<br>
  speed double precision,<br>
  dist double precision,<br>
  shape_utm geometry,<br>
  lokalitet character(128),<br>
  cowid integer  </p>
  
  <p>Id: Primary key There are indexes on datetime,lokalitet,cowid,gpsstatus, gist-index on shape and shape_utm. </p>