Home > database >  Geography function over a column
Geography function over a column

Time:07-24

I am trying to use the st_makeline() function in order to create lines for every points and the next one in a single column. Do I need to create another column with the 2 points already ?

with t1 as(
SELECT *, ST_GEOGPOINT(cast(long as float64) , cast(lat as float64))  geometry FROM `my_table.faissal.trajets_flix` 
where id = 1
order by index_loc
)

select index_loc geometry
from t1

enter image description here

When visualized on the map.

enter image description here

CodePudding user response:

Consider also below simple and cheap option

select st_geogfromtext(format('linestring(%s)', 
    string_agg(long || ' ' || lat order by index_loc))
  ) as path
from `my_table.faissal.trajets_flix`
where id = 1             

if applied to sample data in your question - output is

enter image description here

which is visualized as

enter image description here

  • Related