Namn

ST_Collect — Skapar en GeometryCollection eller Multi* geometri från en uppsättning geometrier.

Synopsis

geometry ST_Collect(geometry g1, geometry g2);

geometry ST_Collect(geometry[] g1_array);

geometry ST_Collect(geometry set g1field);

Beskrivning

Samlar geometrier till en geometrisamling. Resultatet är antingen en Multi* eller en GeometryCollection, beroende på om indatageometrierna har samma eller olika typer (homogena eller heterogena). De ingående geometrierna lämnas oförändrade inom samlingen.

Variant 1: accepterar två inmatningsgeometrier

Variant 2: accepterar en array av geometrier

Variant 3: Aggregerad funktion som tar emot en rad med geometrier.

[Varning]

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).

Tillgänglighet: 1.4.0 - ST_Collect(geomarray) introducerades. ST_Collect förbättrades för att hantera fler geometrier snabbare.

Denna funktion stöder 3d och kommer inte att tappa z-index.

Denna metod stöder cirkulära strängar och kurvor.

Exempel

Two-input variant.

Samla 2D-punkter.

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

Samla 3D-punkter.

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

Samla kurvor.

Code
SELECT ST_Collect(
        'CIRCULARSTRING(220268 150415,220227 150505,220227 150406)',
        'CIRCULARSTRING(220227 150406,2220227 150407,220227 150406)');
Rasterutdata
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.

Använda en array constructor för en subquery.

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

Använda en array constructor för värden.

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

Aggregate variant.

Skapa flera samlingar genom att gruppera geometrier i en tabell.

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

Se även

ST_Dump, ST_Union