Convert a temporal spatial value to a spatiotemporal box
tspatial::stbox
SELECT tgeompoint '[Point(1 1)@2001-01-01, Point(3 3)@2001-01-03]'::tstzspan; -- [2001-01-01, 2001-01-03] SELECT tgeompoint '[Point(1 1)@2001-01-01, Point(3 3)@2001-01-03]'::stbox; -- STBOX XT(((1,1),(3,3)),[2001-01-01, 2001-01-03]) SELECT tgeography '[Point(1 1 1)@2001-01-01, Point(3 3 3)@2001-01-03]'::stbox; -- SRID=4326;GEODSTBOX ZT(((1,1,1),(3,3,3)),[2001-01-01, 2001-01-03])
Convert between a temporal geometry and a temporal geography
tgeometry::tgeography
tgeography::tgeometry
tgeompoint::tgeogpoint
tgeogpoint::tgeompoint
SELECT asText((tgeompoint '[Point(0 0)@2001-01-01, Point(0 1)@2001-01-02)')::tgeogpoint); -- [POINT(0 0)@2001-01-01, POINT(0 1)@2001-01-02) SELECT asText((tgeography 'Linestring(0 0,1 1)@2001-01-01')::tgeometry); -- LINESTRING(0 0,1 1)@2001-01-01
A common way to store temporal points in PostGIS is to represent them as geometries of type LINESTRING M
and use the M dimension to encode timestamps as seconds since 1970-01-01 00:00:00. These time-enhanced geometries, called trajectories, can be validated with the function ST_IsValidTrajectory
to verify that the M value is growing from each vertex to the next. Trajectories can be manipulated with the functions ST_ClosestPointOfApproach
, ST_DistanceCPA
, and ST_CPAWithin
. Temporal point values can be converted to/from PostGIS trajectories.
Convert between a temporal point and a PostGIS trajectory
tpoint::geo
geo::tpoint
SELECT ST_AsText((tgeompoint 'Point(0 0)@2001-01-01')::geometry); -- POINT M (0 0 978307200) SELECT ST_AsText((tgeompoint '{Point(0 0)@2001-01-01, Point(1 1)@2001-01-02, Point(1 1)@2001-01-03}')::geometry); -- MULTIPOINT M (0 0 978307200,1 1 978393600,1 1 978480000)" SELECT ST_AsText((tgeompoint '[Point(0 0)@2001-01-01, Point(1 1)@2001-01-02)')::geometry); -- LINESTRING M (0 0 978307200,1 1 978393600) SELECT ST_AsText((tgeompoint '{[Point(0 0)@2001-01-01, Point(1 1)@2001-01-02), [Point(1 1)@2001-01-03, Point(1 1)@2001-01-04), [Point(1 1)@2001-01-05, Point(0 0)@2001-01-06)}')::geometry); /* MULTILINESTRING M ((0 0 978307200,1 1 978393600),(1 1 978480000,1 1 978566400), (1 1 978652800,0 0 978739200)) */ SELECT ST_AsText((tgeompoint '{[Point(0 0)@2001-01-01, Point(1 1)@2001-01-02), [Point(1 1)@2001-01-03], [Point(1 1)@2001-01-05, Point(0 0)@2001-01-06)}')::geometry); /* GEOMETRYCOLLECTION M (LINESTRING M (0 0 978307200,1 1 978393600), POINT M (1 1 978480000),LINESTRING M (1 1 978652800,0 0 978739200)) */
SELECT asText(geometry 'LINESTRING M (0 0 978307200,0 1 978393600, 1 1 978480000)'::tgeompoint); -- [POINT(0 0)@2001-01-01, POINT(0 1)@2001-01-02, POINT(1 1)@2001-01-03]; SELECT asText(geometry 'GEOMETRYCOLLECTION M (LINESTRING M (0 0 978307200,1 1 978393600), POINT M (1 1 978480000),LINESTRING M (1 1 978652800,0 0 978739200))'::tgeompoint); /* {[POINT(0 0)@2001-01-01, POINT(1 1)@2001-01-02], [POINT(1 1)@2001-01-03], [POINT(1 1)@2001-01-05, POINT(0 0)@2001-01-06]} */