【问题标题】:Cartodb SQL: ST_MakeLine ConversionCartodb SQL:ST_MakeLine 转换
【发布时间】:2018-06-22 18:24:00
【问题描述】:

我正在使用 Cartodb 映射一些我想将唯一 ID 与线连接的 GPS 点。我在编写 SQL 时使用了这个 site 作为参考。 SQL 执行没有任何错误,但我的地图没有生成。

这是我正在运行 SQL 的 CSV 数据集:

X           Y         track_fid       track_seg_point_id    time
-87.5999    41.7083     0              0                   2/17/2018 16:10
-87.74214   41.91581    0              0                   2/17/2018 16:11
-87.6005    41.7081     0              0                   2/17/2018 16:14
-87.6584    41.8265     0              1                   2/17/2018 16:41
-87.63029   41.85842    0              1                   2/17/2018 16:59
-87.7308    41.8893     0              1                   2/17/2018 17:07
-87.59857   41.708393   0              2                   2/17/2018 17:08
-87.5995    41.7081     0              2                   2/17/2018 17:15
-87.68106   41.799088   0              2                   2/17/2018 17:47

这是我的 SQL:

SELECT 
    ST_MakeLine(the_geom_webmercator ORDER BY time ASC) AS the_geom_webmercator,
    extract(hour from time) as hour,
    track_seg_point_id AS cartodb_id


    FROM snow_plow_data

    GROUP BY
    track_seg_point_id,
    hour

这是我的 SQL 生成的表:

Hour       cartodb_id
16         0
16         1
17         1
17         2

任何想法或建议都会很好地解释为什么我的地图点没有显示为线。

【问题讨论】:

    标签: sql cartodb


    【解决方案1】:

    如果您使用的是 BUILDER UI,您可以添加Create Lines from Points analysis,按time 排序并按track_fid 字段(或track_seg_point_id,不知道您要使用哪个字段)分组您的行:

    另一方面,如果您想使用 SQL 控制台执行此操作。 CARTO BUILDER 现在不仅需要cartodb_idthe_geom_webmercator,还需要the_geom 列。因此,您需要将最后一个字段添加到您的查询中。像这样的东西应该可以工作:

    WITH lines as (
      SELECT 
          ST_MakeLine(the_geom_webmercator ORDER BY time ASC) AS the_geom_webmercator,
          ROW_NUMBER() OVER() as cartodb_id
      FROM 
          tracks
      GROUP BY
          track_seg_point_id)
    
    SELECT
        ST_Transform(the_geom_webmercator, 4326) as the_geom,
        *
    FROM
        lines
    

    【讨论】:

    • 嗨@ramiroaznar 感谢您的回复。您给出的 SQL 运行成功,但它返回一个包含 the_geomcartodb_id 列的表。 the_geom 列的所有值也为空
    • 您的第一个答案通过Create Lines from Points 有效,谢谢!
    • 嗨 @ramiroaznar 我正在尝试你的 SQL 答案,但是 the_geom 列的结果是 null,你知道为什么吗?
    • 您能否发布另一个问题,其中包含您正在应用的确切查询以及指向您的数据集的链接?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多