Postgres split LineStrings and convert

情到浓时终转凉″ 提交于 2019-12-11 14:48:13

问题


my question is how to build a function in PL/pgSQL to do this :

i have many linestrings like this.

Linestring((3.584731 60.739211,3.590472 60.738030,3.592740 60.736220))

I need to split every Linestring in a Substring and split it up again in 2 coordinates like this.

3.584731 60.739211  
x1            y1      

3.590472 60.738030 
x2            y2     


3.592740 60.736220
x3              y3

And so on with the other points. Save the answers and converting into a double so I can calculate with the points.


回答1:


Use ST_DumpPoints like this:

SELECT ST_X(d.geom), ST_Y(d.geom)
FROM ST_DumpPoints(
    'Linestring(3.584731 60.739211,3.590472 60.738030,3.592740 60.736220)') AS d;

   st_x   |   st_y    
----------+-----------
 3.584731 | 60.739211
 3.590472 |  60.73803
  3.59274 |  60.73622
(3 rows)


来源:https://stackoverflow.com/questions/27035149/postgres-split-linestrings-and-convert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!