如何使GeoJSON FeatureCollection在PostgreSQL中的指定列处被截断?

时间:2019-10-04 10:43:07

标签: postgresql postgis geojson

我有一个表“ terminals_data”及其GPS终端位置:

+-------------+------------+------------------+--------------+ | terminal_id | location | gnss_date | trackline_id | +-------------+------------+------------------+--------------+ | 0001 | POINT(x y) | 2019-10-04 13:20 | 1 | +-------------+------------+------------------+--------------+ | 0001 | POINT(x y) | 2019-10-04 13:25 | 1 | +-------------+------------+------------------+--------------+ | 0001 | POINT(x y) | 2019-10-04 14:05 | 2 | +-------------+------------+------------------+--------------+ | 0001 | POINT(x y) | 2019-10-04 14:10 | 2 | +-------------+------------+------------------+--------------+ | 0002 | POINT(x y) | 2019-10-04 13:21 | 1 | +-------------+------------+------------------+--------------+ | 0002 | POINT(x y) | 2019-10-04 13:26 | 1 | +-------------+------------+------------------+--------------+

有时GPS终端失去互联网连接,服务器上的GPS数据丢失。此行程反映在trackline_id列中。

我有我的SQL查询,它返回GPS终端的一条跟踪线:

SELECT feature.terminal_id,
    jsonb_build_object(
        'type', 'FeatureCollection',
        'features', jsonb_agg(feature.jsonb_build_object)) AS track_geojson

    FROM (

        SELECT
            terminal_id,
            jsonb_build_object(
                'type', 'Feature',
                'geometry', ST_AsGeoJson(
                    ST_MakeLine(location::geometry)
                )::jsonb
                --'properties', jsonb_build_object('terminal_id', terminal_id)
            )
            AS jsonb_build_object

        FROM terminals_data

        GROUP BY terminal_id

    ) as feature

WHERE terminal_id = '0001'

GROUP BY feature.terminal_id

结果: { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "LineString", "coordinates": [ [x, y], [x, y], [x, y], [x, y], ] } } ] }

因此,我想在终端trackline_id截断的终端0001的结果“ track_geojson”列中获取GeoJSON对象,如下所示:

{
"type": "FeatureCollection",
"features": [
    {
        "type": "Feature",
        "geometry": {
            "type": "LineString",
            "coordinates": [
                [x, y],
                [x, y],
            ]
        }
    },
    {
        "type": "Feature",
        "geometry": {
            "type": "LineString",
            "coordinates": [
                [x, y],
                [x, y],
            ]
        }
    }
]

}

每个终端ID的每个trackline_id具有两个功能。

该怎么做?

0 个答案:

没有答案