Round the coordinate values to a number of decimal places
round(tpoint,integer=0) → tpoint
SELECT asText(round(tgeompoint '{Point(1.12345 1.12345 1.12345)@2001-01-01, Point(2 2 2)@2001-01-02, Point(1.12345 1.12345 1.12345)@2001-01-03}', 2)); /* {POINT Z (1.12 1.12 1.12)@2001-01-01, POINT Z (2 2 2)@2001-01-02, POINT Z (1.12 1.12 1.12)@2001-01-03} */ SELECT asText(round(tgeogpoint 'Point(1.12345 1.12345)@2001-01-01', 2)); -- POINT(1.12 1.12)@2001-01-01
Return an array of fragments of the temporal point which are simple
makeSimple(tpoint) → tgeompoint[]
SELECT asText(makeSimple(tgeompoint '[Point(0 0)@2001-01-01, Point(1 1)@2001-01-02, Point(0 0)@2001-01-03]')); /* {"[POINT(0 0)@2001-01-01, POINT(1 1)@2001-01-02)", "[POINT(1 1)@2001-01-02, POINT(0 0)@2001-01-03]"} */ SELECT asText(makeSimple(tgeompoint '[Point(0 0 0)@2001-01-01, Point(1 1 1)@2001-01-02, Point(2 0 2)@2001-01-03, Point(0 0 0)@2001-01-04]')); /* {"[POINT Z (0 0 0)@2001-01-01, POINT Z (1 1 1)@2001-01-02, POINT Z (2 0 2)@2001-01-03, POINT Z (0 0 0)@2001-01-04]"} */ SELECT asText(makeSimple(tgeompoint '[Point(0 0)@2001-01-01, Point(1 1)@2001-01-02, Point(0 1)@2001-01-03, Point(1 0)@2001-01-04]')); /* {POINT Z (1.12 1.12 1. {"[POINT(0 0)@2001-01-01, POINT(1 1)@2001-01-02, POINT(0 1)@2001-01-03)", "[POINT(0 1)@2001-01-03, POINT(1 0)@2001-01-04]"} */ SELECT asText(makeSimple(tgeompoint '{[Point(0 0 0)@2001-01-01, Point(1 1 1)@2001-01-02], [Point(1 1 1)@2001-01-03, Point(0 0 0)@2001-01-04]}')); /* {"{[POINT Z (0 0 0)@2001-01-01, POINT Z (1 1 1)@2001-01-02], [POINT Z (1 1 1)@2001-01-03, POINT Z (0 0 0)@2001-01-04]}"} */
Construct a geometry/geography with M measure from a temporal point and a temporal float
geoMeasure(tpoint,tfloat,segmentize=false) → geo
The last segmentize
argument states whether the resulting value is a either Linestring M
or a MultiLinestring M
where each component is a segment of two points.
SELECT st_astext(geoMeasure(tgeompoint '{Point(1 1 1)@2001-01-01, Point(2 2 2)@2001-01-02}', '{5@2001-01-01, 5@2001-01-02}')); -- MULTIPOINT ZM (1 1 1 5,2 2 2 5) SELECT st_astext(geoMeasure(tgeogpoint '{[Point(1 1)@2001-01-01, Point(2 2)@2001-01-02], [Point(1 1)@2001-01-03, Point(1 1)@2001-01-04]}', '{[5@2001-01-01, 5@2001-01-02],[7@2001-01-03, 7@2001-01-04]}')); -- GEOMETRYCOLLECTION M (POINT M (1 1 7),LINESTRING M (1 1 5,2 2 5)) SELECT st_astext(geoMeasure(tgeompoint '[Point(1 1)@2001-01-01, Point(2 2)@2001-01-02, Point(1 1)@2001-01-03]', '[5@2001-01-01, 7@2001-01-02, 5@2001-01-03]', true)); -- MULTILINESTRING M ((1 1 5,2 2 5),(2 2 7,1 1 7))
A typical visualization for mobility data is to show on a map the trajectory of the moving object using different colors according to the speed. Figure 8.1, “Visualizing the speed of a moving object using a color ramp in QGIS.” shows the result of the query below using a color ramp in QGIS.
WITH Temp(t) AS ( SELECT tgeompoint '[Point(0 0)@2001-01-01, Point(1 1)@2001-01-05, Point(2 0)@2001-01-08, Point(3 1)@2001-01-10, Point(4 0)@2001-01-11]' ) SELECT ST_AsText(geoMeasure(t, round(speed(t) * 3600 * 24, 2), true)) FROM Temp; -- MULTILINESTRING M ((0 0 0.35,1 1 0.35),(1 1 0.47,2 0 0.47),(2 0 0.71,3 1 0.71), -- (3 1 1.41,4 0 1.41))
The following expression is used in QGIS to achieve this. The scale_linear
function transforms the M value of each composing segment to the range [0, 1]. This value is then passed to the ramp_color
function.
ramp_color( 'RdYlBu', scale_linear( m(start_point(geometry_n($geometry,@geometry_part_num))), 0, 2, 0, 1) )
Transform a temporal geometric point into the coordinate space of a Mapbox Vector Tile
asMVTGeom(tpoint,bounds,extent=4096,buffer=256,clip=true) → (geom,times)
The result is a couple composed of a geometry
value and an array of associated timestamp values encoded as Unix epoch. The parameters are as follows:
tpoint
is the temporal point to transform
bounds
is an stbox
defining the geometric bounds of the tile contents without buffer
extent
is the tile extent in tile coordinate space
buffer
is the buffer distance in tile coordinate space
clip
is a Boolean that determines if the resulting geometries and timestamps should be clipped or not
SELECT ST_AsText((mvt).geom), (mvt).times FROM (SELECT asMVTGeom(tgeompoint '[Point(0 0)@2001-01-01, Point(100 100)@2001-01-02]', stbox 'STBOX X((40,40),(60,60))') AS mvt ) AS t; -- LINESTRING(-256 4352,4352 -256) | {946714680,946734120} SELECT ST_AsText((mvt).geom), (mvt).times FROM (SELECT asMVTGeom(tgeompoint '[Point(0 0)@2001-01-01, Point(100 100)@2001-01-02]', stbox 'STBOX X((40,40),(60,60))', clip:=false) AS mvt ) AS t; -- LINESTRING(-8192 12288,12288 -8192) | {946681200,946767600}