Compartilhar via


Coleção de Geometria

A GeometryCollection é uma coleção de zero ou mais geometry ou geography instâncias. Um GeometryCollection pode estar vazio.

Instâncias de GeometryCollection

Instâncias aceitas

Para que uma GeometryCollection instância seja aceita, ela deve ser uma instância vazia GeometryCollection ou todas as instâncias que compõem a GeometryCollection instância devem ser aceitas. O exemplo a seguir mostra exemplos aceitos.

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)))';  

O exemplo a seguir lança um System.FormatException porque a instância LinesString dentro da instância GeometryCollection não é aceita.

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

Instâncias válidas

Uma GeometryCollection instância é válida quando todas as instâncias que compõem a GeometryCollection instância são válidas. O exemplo a seguir mostra três instâncias válidas GeometryCollection e uma instância que não é válida.

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ão é válido porque a Polygon instância na GeometryCollection instância não é válida.

Para obter mais informações sobre instâncias aceitas e válidas, consulte Point, MultiPoint, LineString, MultiLineString, Polygon e MultiPolygon.

Exemplos

O exemplo a seguir cria uma geometry``GeometryCollection instância com valores Z no SRID 1 que contém uma Point instância e uma Polygon instância.

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

Consulte Também

Dados Espaciais (SQL Server)