名前

ST_Collect — ジオメトリの集合からジオメトリコレクションまたはマルチ系ジオメトリを生成します。

概要

geometry ST_Collect(geometry g1, geometry g2);

geometry ST_Collect(geometry[] g1_array);

geometry ST_Collect(geometry set g1field);

説明

ジオメトリを集めてジオメトリコレクションにします。結果はマルチ系ジオメトリかジオメトリコレクションかのいずれかで、この差は、入力ジオメトリのタイプが同じか異なるか(均質か不均質か)で決まります。入力ジオメトリはコレクション内で変更されることはありません。

1番目の形式: 二つの入力ジオメトリを受け付ける。

2番目の形式: ジオメトリの配列を受け付ける。

3番目の形式: ジオメトリの行集合を受け付ける集約関数。

[警告]

ST_Collect does not dissolve boundaries or resolve overlaps. Collecting overlapping polygons can produce an invalid MultiPolygon. If the result must be a valid polygonal geometry with overlaps merged, use ST_Union instead. ST_Union also splits linestrings at intersections and may return a single geometry after dissolving boundaries.

If any input geometry is a collection (Multi* or GeometryCollection), ST_Collect returns a GeometryCollection, since that is the only type which can contain nested collections. To prevent this, use ST_Dump in a subquery to expand input collections to their atomic elements (see example below).

Availability: 1.4.0 - ST_Collect(geometry)が導入されました。ST_Collectがより多くのジオメトリをより早く扱えるよう強化されました。

この関数は3次元に対応し、Z値を削除しません。

このメソッドは曲線ストリングと曲線に対応しています。

Two-input variant.

2次元ポイントを収集します。

Code
SELECT ST_Collect(
    'POINT(1 2)',
    'POINT(-2 3)' );
出力:
MULTIPOINT((1 2),(-2 3))
Figure
Geometry figure for visual-st-collect-01

2次元ポイントの収集

Code
SELECT ST_Collect(
        'POINT(1 2 3)',
        'POINT(1 2 4)' );
出力:
MULTIPOINT(1 2 3,1 2 4)
Figure
Geometry figure for visual-st-collect-02

曲線を収集します。

Code
SELECT ST_Collect(
        'CIRCULARSTRING(220268 150415,220227 150505,220227 150406)',
        'CIRCULARSTRING(220227 150406,2220227 150407,220227 150406)');
出力:
MULTICURVE(CIRCULARSTRING(220268 150415,220227 150505,220227 150406),
CIRCULARSTRING(220227 150406,2220227 150407,220227 150406))
Figure
Geometry figure for visual-st-collect-03

Array variant.

サブクエリから配列を生成するコンストラクタの使用。

Code
SELECT ST_Collect(ARRAY(SELECT geom FROM sometable));

値から配列を生成するコンストラクタの使用。

Code
SELECT ST_Collect(
        ARRAY[ 'LINESTRING(1 2,3 4)'::geometry,
            'LINESTRING(3 4,4 5)'::geometry ] ) As wktcollect;
出力:
MULTILINESTRING((1 2,3 4),(3 4,4 5))
Figure
Geometry figure for visual-st-collect-04

Aggregate variant.

テーブル内のジオメトリのグループ化による複数コレクションを生成します。

Code
SELECT stusps, ST_Collect(geom) AS geom
FROM (
  SELECT stusps, (ST_Dump(geom)).geom AS geom
  FROM somestatetable
) AS f
GROUP BY stusps;

関連情報

ST_Dump, ST_Union