A temporal value can be converted into a compatible type using the notation CAST(ttype1 AS ttype2)
or ttype1::ttype2
.
Convert a temporal value to a bounding box
ttype::tstzspan
tnumber::{numspan,tbox}
tpoint::stbox
SELECT tint '[1@2001-01-01, 2@2001-01-03]'::tstzspan; -- [2001-01-01, 2001-01-03] SELECT ttext '(A@2001-01-01, B@2001-01-03, C@2001-01-05]'::tstzspan; -- (2001-01-01, 2001-01-05] SELECT tgeompoint '[Point(1 1)@2001-01-01, Point(3 3)@2001-01-03]'::tstzspan; -- [2001-01-01, 2001-01-03]
SELECT tint '[1@2001-01-01, 2@2001-01-03]'::intspan; -- [1, 3) SELECT tfloat '(1@2001-01-01, 3@2001-01-03, 2@2001-01-05]'::floatspan; -- (1, 3] SELECT tfloat 'Interp=Step;(1@2001-01-01, 3@2001-01-03, 2@2001-01-05]'::floatspan; -- [1, 3]
SELECT tint '[1@2001-01-01, 2@2001-01-03]'::tbox; -- TBOXINT XT((1,2),[2001-01-01,2001-01-03]) SELECT tfloat '(1@2001-01-01, 3@2001-01-03, 2@2001-01-05]'::tbox; -- TBOXFLOAT XT((1,3),[2001-01-01,2001-01-05]) 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 tgeogpoint '[Point(1 1)@2001-01-01, Point(3 3)@2001-01-03]'::stbox; -- SRID=4326;GEODSTBOX XT(((1,1),(3,3)),[2001-01-01, 2001-01-03 00:00:00+01]) SELECT tgeogpoint '[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 integer and a temporal float
tint::tfloat
tfloat::tint
SELECT tint '[1@2001-01-01, 2@2001-01-03]'::tfloat; -- Interp=Step;[1@2001-01-01, 2@2001-01-03] SELECT tint '[1@2001-01-01, 2@2001-01-03, 3@2001-01-05]'::tfloat; -- Interp=Step;[1@2001-01-01, 2@2001-01-03, 3@2001-01-05] SELECT tfloat 'Interp=Step;[1.5@2001-01-01, 2.5@2001-01-03]'::tint; -- [1@2001-01-01, 2@2001-01-03] SELECT tfloat '[1.5@2001-01-01, 2.5@2001-01-03]'::tint; -- ERROR: Cannot cast temporal float with linear interpolation to temporal integer
Convert a temporal geometry point to a temporal geography point
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((tgeogpoint 'Point(0 0)@2001-01-01')::tgeompoint); -- {POINT(0 0)@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]} */