Reputation: 345
I have a column in postgis like:
[{"lang":-122.39726983952495,"lat":37.789519907547806},{"lang":-122.39703479547161,"lat":37.78933265166566}]
I need to draw the line on OpenLayers Map by converting this column to geometry.
Upvotes: 1
Views: 686
Reputation: 23686
step-by-step demo:db<>fiddle (From JSON to line as geometry)
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
Upvotes: 2