[postgis-users] Looking for a points to moving average path function

Stephen Woodbridge woodbri at swoodbridge.com
Wed Feb 23 10:51:34 PST 2011


Hi All,

I have a table of points and I would like to generate a path from these 
points.

This works very well for the raw points:

select device, makeline(p) as the_geom from
       (select device, p from gpspoints order by seq) as foo
         group by device;


I would like to smooth these points using a moving average where if the 
number of points in the average is say 3 then the points are:

p[1]
(p[1]+p[2])/2
(p[1]+p[2]+p[3])/3
(p[2]+p[3]+p[4])/3
...
(p[n-2]+p[n-1]+p[n])/3

and these points are then used in makeline().

So I can do a brute force iterative function, but it seems like there 
should be a more elegant solution.

Thoughts, code snippets, etc?

I'm working with postgresql 8.3, 8.4 and postgis 1.5 at the moment.

-Steve



More information about the postgis-users mailing list