GeometryCollection

Une GeometryCollection est une collection d'aucune ou de plusieurs instances geometry ou geography.

Instances GeometryCollection

Instances acceptées

Pour qu'une instance GeometryCollection soit acceptée, il doit s'agir soit d'une instance GeometryCollection vide, soit d'une instance GeometryCollection dont toutes les instances qui la composent sont acceptées. L'exemple suivant montre des instances acceptées.

DECLARE @g1 geometry = 'GEOMETRYCOLLECTION EMPTY';
DECLARE @g2 geometry = 'GEOMETRYCOLLECTION(LINESTRING EMPTY,POLYGON((-1 -1, -1 -5, -5 -5, -5 -1, -1 -1)))';
DECLARE @g3 geometry = 'GEOMETRYCOLLECTION(LINESTRING(1 1, 3 5),POLYGON((-1 -1, -1 -5, -5 -5, -5 -1, -1 -1)))';

L'exemple suivant provoque une exception System.FormatException car l'instance LinesString de l'instance GeometryCollection n'est pas acceptée.

DECLARE @g geometry = 'GEOMETRYCOLLECTION(LINESTRING(1 1), POLYGON((-1 -1, -1 -5, -5 -5, -5 -1, -1 -1)))';

Instances valides

Une instance GeometryCollection est valide lorsque toutes les instances qui composent l'instance GeometryCollection sont valides. L'exemple suivant montre trois instances GeometryCollection valides et une instance non valide.

DECLARE @g1 geometry = 'GEOMETRYCOLLECTION EMPTY';
DECLARE @g2 geometry = 'GEOMETRYCOLLECTION(LINESTRING EMPTY,POLYGON((-1 -1, -1 -5, -5 -5, -5 -1, -1 -1)))';
DECLARE @g3 geometry = 'GEOMETRYCOLLECTION(LINESTRING(1 1, 3 5),POLYGON((-1 -1, -1 -5, -5 -5, -5 -1, -1 -1)))';
DECLARE @g4 geometry = 'GEOMETRYCOLLECTION(LINESTRING(1 1, 3 5),POLYGON((-1 -1, 1 -5, -5 5, -5 -1, -1 -1)))';
SELECT @g1.STIsValid(), @g2.STIsValid(), @g3.STIsValid(), @g4.STIsValid();

@g4 n'est pas valide car l'instance Polygon comprise dans l'instance GeometryCollection n'est pas valide.

Pour plus d'informations sur les instances acceptées et valides, consultez Point, MultiPoint, LineString, MultiLineString, Polygon et MultiPolygon.

Exemples

L'exemple suivant instancie une GeometryCollectiongeometry avec les valeurs Z dans SRID 1 contenant une instance Point et une instance Polygon.

DECLARE @g geometry;
SET @g = geometry::STGeomCollFromText('GEOMETRYCOLLECTION(POINT(3 3 1), POLYGON((0 0 2, 1 10 3, 1 0 4, 0 0 2)))', 1);