Un valor temporal se puede convertir en un tipo compatible usando la notación CAST(ttype1 AS ttype2)
o ttype1::ttype2
.
Convertir un valor temporal a un cuadro delimitador
ttype::tstzspan
tnumber::{span,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])
Convertir entre un entero temporal y un flotante temporal
tint::tfloat
tfloat::tint
SELECT tint '[1@2001-01-01, 2@2001-01-03]'::tfloat; -- Interp=Step;[1@2001-01-01 00:00:00+00, 2@2001-01-03 00:00:00+00] 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 00:00:00+00, 2@2001-01-03 00:00:00+00] SELECT tfloat '[1.5@2001-01-01, 2.5@2001-01-03]'::tint; -- ERROR: Cannot cast temporal float with linear interpolation to temporal integer
Convertir entre un punto geométrico temporal y un punto geográfico temporal
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}
Una forma común de almacenar puntos temporales en PostGIS es representarlos como geometrías de tipo LINESTRING M
y utilizar la dimensión M para codificar marcas de tiempo como segundos desde 1970-01-01 00:00:00. Estas geometrías aumentadas con tiempo, llamadas trayectorias, se pueden validar con la función ST_IsValidTrajectory
para verificar quel el valor M está creciendo de cada vértice al siguiente. Las trayectorias se pueden manipular con las funciones ST_ClosestPointOfApproach
, ST_DistanceCPA
y ST_CPAWithin
. Los valores de puntos temporales se pueden convertir a/desde trayectorias de PostGIS.
Convertir entre un punto temporal y una trayectoria PostGIS
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]} */