What is an efficient way to convert a set of ordered latitude longitude pairs into a Linestring in PostGIS?

StackOverflow https://stackoverflow.com/questions/21937119

  •  14-10-2022
  •  | 
  •  

문제

I can convert it into WKT and then to a Linestring but I think there are more efficient ways to do it.

올바른 솔루션이 없습니다

다른 팁

Presuming your data looks like this:

enter image description here

You may convert the set of ordered longitude/latitude pairs into linestrings like this:

SELECT ST_AsText(ST_MakeLine(q.f, q.t)) FROM
  (SELECT (SELECT ST_MakePoint(c.long_from, c.lat_from) AS f),
  (SELECT ST_MakePoint(c.long_to, c.lat_to) AS t) 
   FROM lonlatset c) AS q;

And here's the result:

enter image description here

Try to remember that it is very important to respect the proper coordinates order: first the longitude, and second the latitude!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top