PostGIS/CartoDB:存储MultiLineString中每个点的时间戳

ffl*_*dro 6 gis postgis

我正在使用CartoDB作为我的应用程序的PostGIS服务器.

我需要存储轨道并为每个轨道点坐标对关联一个时间戳,以便进行查询give me the distance traveled between 12AM and 12PM on day X.

在CartoDB我只能创建3种类型的表:点对多点,MULTILINESTRING和MULTIPOLYGON.要插入曲目,我正在使用MULTILINESTRING表.

我的第一个尝试是将时间戳作为MULTILINESTRING中每个点的Z索引插入,但是我总是得到一个 ERROR: Geometry has Z dimension but column does not.

如何在"普通"PostGIS数据库中实现这一目标,以及如何在CartoDB PostGIS实现中实现它?

更新1:

因此,在jatorre回答之后,我创建了一个JSFiddle示例作为练习练习.但是我得到了不连贯的结果.

在上面的例子中,我有两个表具有相同的两个数据集.然而,一个是一个MULTILINESTRING表,其中每一行代表一个segment,另一个是MULTIPOINT我存储每组segment坐标的表.

然后我查询这两个表来获取total distance of segments according to transport mode.我觉得我很清楚地得到了jattore的idead,但是我不明白为什么我会得到不同的结果CarWalk总距离.任何提示?

解:

距离的微小差异是因为我需要在对points表进行分组之前对表进行排序segment.这是我当前的查询,以获取根据传输模式行进的总距离和时间:

WITH segments AS 
  (SELECT ST_Makeline(pts.the_geom_webmercator) as the_geom, (MAX(pts.timestamp) - MIN(pts.timestamp)) AS time, paths.transport_mode, paths.cartodb_id AS id
   FROM (SELECT * FROM points ORDER BY track_id, path_id, timestamp ASC) AS pts JOIN paths ON pts.path_id=paths.cartodb_id
   WHERE paths.user_id=1
   GROUP BY id, transport_mode)
SELECT SUM(ST_Length(segments.the_geom)) AS distance, SUM(segments.time), segments.transport_mode
FROM segments
GROUP BY segments.transport_mode
ORDER BY distance
Run Code Online (Sandbox Code Playgroud)

jat*_*rre 3

嗯,这有点取决于。

假设您有一个 GPS 轨迹结构。在这种情况下,您将这些 GPS 轨迹转换为段(只有两个坐标的线),并且可以将 start_time 和 end_time 分隔开。

然后,使用该结构,您可以在这些日期之间使用 WHERE 子句执行 SELECT 操作,并对各段的 ST_Length_Spheroid 求和。

如果您想在一个查询中完成所有操作,请考虑到您有一张包含以下内容的表:

the_geom(point), timestamp, cartodb_id
Run Code Online (Sandbox Code Playgroud)

你可以做类似的事情

WITH segments AS 
(SELECT ST_MakeLine(
   the_geom,
   (SELECT the_geom FROM tracks as st WHERE st.cartodb_id = t.cartodb_id+1)
) as the_geom
FROM traces as t WHERE timestamp BETWEEN ...)
SELECT sum(ST_Length_Spheroid(segments.the_geom)
Run Code Online (Sandbox Code Playgroud)

这完全是我的想法……但我希望你能明白。

您不需要使用 Z 维度,实际上我们不太支持这一点。