如何从linetring postgis获取积分

时间:2014-06-27 05:39:16

标签: postgresql postgis

我有Linestring(0 0,2 4,5 5);

我需要以下列形式输出:

x (1st cell)   ||    y (2nd cell)

0              ||    0

2              ||    4

5              ||    5 

多边形也一样。 怎么做?

1 个答案:

答案 0 :(得分:2)

您可以将ST_X和ST_Y与ST_PointN结合使用以获取各个点的x和y,并使用generate_series为线串的每个点创建索引,例如

with line as (select ST_GeomFromText('LINESTRING(0 0, 2 4, 5 5)') as geom)
    select ST_X(ST_PointN(geom,num)) as x, 
           ST_Y(ST_PointN(geom,num)) as y 
    from line,
(select generate_series(1, (select ST_NumPoints(geom) from line)) as num) 
    as series;