我在postgis中有一栏,例如:
[{"lang":-122.39726983952495,"lat":37.789519907547806},{"lang":-122.39703479547161,"lat":37.78933265166566}]
我需要通过将此列转换为几何来在OpenLayers Map上画线。
答案 0 :(得分:2)
step-by-step demo:db<>fiddle(从JSON到线作为几何)
SELECT
st_makeline( -- 5
array_agg(point.point) -- 4
)
FROM
my_table,
json_array_elements(my_points) AS elems, -- 1
st_makepoint( -- 3
(elems ->> 'lang')::numeric, -- 2
(elems ->> 'lat')::numeric
) AS point