• Trajectory Data Type
    Trajectory is a custom data type of PostgreSQL and can be used to store time geometry pairs. There is a constructor to build trajectory object from time geometry pairs.
  • Creating table with trajectory
    CREATE TABLE taxi_ride (id INTEGER PRIMARY KEY, from TEXT, to TEXT, traj Trajectory);
                                
  • Data Insertion
    Insert INTO taxi_ride (id, from, to, traj) VALUES (1, "LA", "NYC", 
                                _trajectory(ARRAY[ROW(POINT(1,2))::tg_pair, 
                                ROW(POINT(3,6))::tg_pair, ROW(POINT(6,8))::tg_pair]));
                                
    Easy way to insert trajectory object is to use the constructor.
  • Example Query
    Lets try a query:
    SELECT COUNT(*) FROM taxi_ride WHERE 
    from = 'Decatur' AND to = 'Lenox' AND traj.start_time > CURRENT_TIMESTAMP -
    INTERVAL '1 day' AND traj.end_time < CURRENT_TIMESTAMP;
    See the paper for more query examples.

Pg-Trajectory have two requirements, PostgreSQL and PostGIS. Before continue make sure you have installed these requirements. We provide two ways to install the extension. One is standard extension installment process in PostgreSQL. In order to do this, you simply need to execute the provided make file which will copy necassary scripts into your Postgres script library. Than, you can execut the queries mentioned in above.
OR
Installation of the extension is as easy as executing bunch of SQL files. Simple script that contains list of SQL files needs to be executed in database for the extension is provided in install.sql. From you psql terminal, you can execute this script or If you have any problem, you can manually execute these SQL's for the installation.

List of Functions
Function Type Signature Return Explanation
_trajectory Both TG_PAIR[] Trajectory Trajectory object constructor
tg_start_time Both TG_PAIR[] Timestamp Start time of trajectory
tg_end_time Both TG_PAIR[] Timestamp End time of trajectory
tg_mbr Region TG_PAIR[] Trajectory MBR of all geometries in trajectory
tg_type Both TG_PAIR[] Enum Geometry type of trajectory
t_duration Both Trajectory Time Interval End time - start time
t_distance Point Trajectory Trajectory Distance Travelled
t_area Region Trajectory Trajectory Trajectory object constructor
t_volume Region Trajectory Trajectory Trajectory object constructor
t_geom_at Both Trajectory, Timestamp Geometry Geometry at the given timestamp. Returns null if there is no geometry
tg_zNormalize Point TG_PAIR[], Integer, Integer GEOMETRY[] normizel value of points
t_euclidean_distance Both Trajectory Real Euclidean distance. See Paper for detail.
t_overlaps Both Trajectory, Trajectory Real True if any geometryies of two trajectories overlaps according to POSTGIS
t_union Region Trajectory,Trajectory Trajectory Union of all geometries. If timestamp is common, union of two geometries is calculated.
t_intersection Region Trajectory,Trajectory Trajectory Intersection of geometries in common timestamp values.
t_jaccard Region Trajectory,Trajectory Real Jaccard of two trajectories. See paper for detail.
t_omax Region Trajectory,Trajectory Real OMAX of two trajectories. See paper for detail.
t_jaccard_star Region Trajectory,Trajectory Real Jaccard Star of two trajectories. See paper for detail.
t_edit_distance Both Trajectory,Trajectory Real Edit distance of two trajectories. See paper for detail.
t_m_distance Both Trajectory,Trajectory Real[] Euclidean distance of point at common timestamps.
t_add_head Both TG_PAIR,Trajectory Trajectory Return new trajectory with given geometry.
t_add_tail Both TG_PAIR,Trajectory Trajectory Return new trajectory with given geometry.
t_drop_head Both Trajectory Trajectory Return new trajectory without first element of tg_pair array.
t_drop_tail Both Trajectory Trajectory Return new trajectory without last element of tg_pair array.
t_update_geom_at Both Timestamp, Geometry, Trajectory Trajectory Return new trajectory with given geometry.