ST_trajAttrsMeanMax applies the MEAN-MAX algorithm to a trajectory object and returns the maximum sliding-window average for a specified attribute field across all window sizes.
Syntax
SETOF record ST_trajAttrsMeanMax(trajectory traj, cstring attr_field_name, out interval duration, out float8 max);Parameters
| Parameter | Description |
|---|---|
traj | The trajectory object. |
attr_field_name | The name of the attribute field to analyze. |
Returns
A set of records, one per window size. Each record contains:
| Column | Type | Description |
|---|---|---|
duration | interval | The length of the sliding window. |
max | float8 | The maximum of all moving averages computed at this window length. |
How it works
The MEAN-MAX algorithm uses a sliding window to compute the average value of the specified attribute field over each time range covered by the window, then returns the maximum of all those averages.

Usage notes
Supported attribute field types:
integerandfloatonly.The attribute field must not contain null values.
Examples
The examples below use a trajectory with four points and a velocity attribute field.
Example 1: Return results as composite records
With traj AS (
Select ST_makeTrajectory('STPOINT', 'LINESTRING(1 1, 6 6, 9 8, 10 12)'::geometry,
ARRAY['2010-01-01 11:30'::timestamp, '2010-01-01 12:30', '2010-01-01 13:30', '2010-01-01 14:30'],
'{"leafcount":4, "attributes":{"velocity": {"type": "float", "length": 8,"nullable": true,"value": [120.0, 130.0, 140.0, 120.0]}, "power": {"type": "float", "length": 4,"nullable": true,"value": [120.0, 130.0, 140.0, 120.0]}}}') a)
Select st_trajAttrsMeanMax(a, 'velocity') from traj;Output:
st_trajattrsmeanmax
---------------------
("@ 1 hour",135)
("@ 2 hours",130)
("@ 3 hours",127.5)
(3 rows)This format is useful for quick inspection. To reference duration or max individually — for example, in a WHERE clause or JOIN — expand the record using .* as shown in Example 2.
Example 2: Expand records into separate columns
With traj AS (
Select ST_makeTrajectory('STPOINT', 'LINESTRING(1 1, 6 6, 9 8, 10 12)'::geometry,
ARRAY['2010-01-01 11:30'::timestamp, '2010-01-01 12:30', '2010-01-01 13:30', '2010-01-01 14:30'],
'{"leafcount":4, "attributes":{"velocity": {"type": "float", "length": 8,"nullable": true,"value": [120.0, 130.0, 140.0, 120.0]}, "power": {"type": "float", "length": 4,"nullable": true,"value": [120.0, 130.0, 140.0, 120.0]}}}') a)
Select (st_trajAttrsMeanMax(a, 'velocity')).* from traj;Output:
duration | max
----------+-------
01:00:00 | 135
02:00:00 | 130
03:00:00 | 127.5
(3 rows)