ST_Collect — 从一组几何图形创建 GeometryCollection 或 Multi* 几何图形。
geometry ST_Collect(geometry g1, geometry g2);
geometry ST_Collect(geometry[] g1_array);
geometry ST_Collect(geometry set g1field);
将几何图形收集到几何图形集合中。 结果是 Multi* 或 GeometryCollection,具体取决于输入几何图形是否具有相同或不同类型(同质或异构)。输入几何图形在集合中保持不变。
第一种形式:接受两个输入几何图形
第二种形式: 接受几何数组
第三种形式: 接受几何行集的聚合函数。
|
|
|
|
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).
可用性:引入了 1.4.0 - ST_Collect(几何)。 ST_Collect已得到增强,可以更快地处理更多几何图形。
该函数支持 3d 并且不会丢失 z-index。
此方法支持圆形字符串和曲线。
Two-input variant.
合并2D点。
SELECT ST_Collect(
'POINT(1 2)',
'POINT(-2 3)' );
MULTIPOINT((1 2),(-2 3))
合并3D点。
SELECT ST_Collect(
'POINT(1 2 3)',
'POINT(1 2 4)' );
MULTIPOINT(1 2 3,1 2 4)
合并曲线。
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))
Array variant.
使用子查询的数组构造函数。
SELECT ST_Collect(ARRAY(SELECT geom FROM sometable));
使用数组构造函数来获取值。
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))
Aggregate variant.
通过在表中对几何进行分组来生成多个集合。
SELECT stusps, ST_Collect(geom) AS geom FROM ( SELECT stusps, (ST_Dump(geom)).geom AS geom FROM somestatetable ) AS f GROUP BY stusps;