2017-03-30 10 views

答えて

0

あなたは()関数のST_PointNで個々の点を抽出することができます。

CREATE TABLE TMP (NUM INT); 
select TOP 100 ROW_NUMBER() OVER() from PUBLIC.M_TABLES ; 

それから私はカウンター・テーブルを使用して、すべてのポイントのST_PointNを適用します、ポイント1、2、3のためにそれを呼び出すために... N 私はカウンタの値を格納しますTMPと呼ばれる一時テーブルを使用し 。

select ST_UnionAggr(CUR_POINT).ST_AsWKT() 
from(
    select NUM, LS.ST_PointN(NUM) as CUR_POINT 
    from(
     select NEW ST_LineString('LINESTRING(0 0, 2 2, 0 2, 0 5)') as LS,  NUM 
     from TMP  
    )nested1  
    where NUM<=LS.ST_NumPoints() 
)nested2 

これは

MULTIPOINT ((0 0),(2 2),(0 2),(0 5)) 

注意を返す:

select NUM, LS.ST_PointN(NUM).ST_WKT() as CUR_POINT 
from(
    select NEW ST_LineString('LINESTRING(0 0, 2 2, 0 2, 0 5)') as LS, NUM 
    from TMP  
)nested1  
where NUM<=LS.ST_NumPoints() 

これは

NUM| CUR_POINT 
1 |POINT (0 0) 
2 |POINT (2 2) 
3 |POINT (0 2) 
4 |POINT (0 5) 

あなたは簡単ST_UnionAggrを使用して凝集()を用いたST_MultiPoint形状にそれらを連結することができる返します:私たちはcou ldは、カウンタテーブルを使用する代わりにループを実行します。

正確な質問については、ウィンドウ関数を使用して3つのST_LineString()を作成し、現在のポイントと次のポイントを結合します。そのようなクエリを記述するための複数の方法は、ここでは一つだ、があります。

select NEW ST_LineString('LineString ('||START_POINT.ST_X()||' '||START_POINT.ST_Y()||','||END_POINT.ST_X()||' '||END_POINT.ST_Y()||')').ST_AsWKT() as LS 
from(
    select CUR_POINT as START_POINT, 
      NEW ST_Point(FIRST_VALUE(CUR_POINT) OVER(order by NUM asc rows BETWEEN 1 following and 1 following))as END_POINT 
    from(
     select NUM, LS.ST_PointN(NUM) as CUR_POINT, LS.ST_NumPoints() as NB_POINTS 
     from(
      select NEW ST_LineString('LINESTRING(0 0, 2 2, 0 2, 0 5)') as LS, NUM 
      from TMP  
     )nested1  
     where NUM<=LS.ST_NumPoints() 
    )nested2 
)nested3 
where END_POINT is not null 

多田:

LS 
LINESTRING (0 0,2 2) 
LINESTRING (2 2,0 2) 
LINESTRING (0 2,0 5) 
関連する問題