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.
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'
(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
Question 1: Is it possible to make the view so that I can define the time interval as well?
e.g. select * form movement_view where observedid=42 and interval='15 minutes' ?
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?
Table definition:
id integer,
gpsstatus character(2),
datetime timestamp without time zone,
lat numeric(9,6),
lon numeric(9,6),
alt numeric(9,4),
time integer,
datafileid integer,
shape geometry,
speed double precision,
dist double precision,
shape_utm geometry,
lokalitet character(128),
cowid integer
Id: Primary key There are indexes on datetime,lokalitet,cowid,gpsstatus, gist-index on shape and shape_utm.