GeometryCollection

Aplica-se a:SQL ServerBanco de Dados SQL do AzureInstância Gerenciada de SQL do Azure

Uma GeometryCollection é uma coleção de zero ou mais instâncias de geometry ou de geography . Uma GeometryCollection pode estar vazia.

Instâncias de GeometryCollection

Instâncias aceitas

Para que uma instância de GeometryCollection seja aceita, ela deve ser uma instância de GeometryCollection vazia ou todas as instâncias que englobam a instância de GeometryCollection devem ser instâncias aceitas. O exemplo a seguir mostra instâncias aceitas.

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 emite uma System.FormatException porque a instância de LinesString na instância de 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 instância de GeometryCollection é válida quando todas as instâncias que englobam a instância de GeometryCollection são válidas. O exemplo a seguir mostra três instâncias de GeometryCollection válidas 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álida porque a instância de Polygon na instância de GeometryCollection não é válida.

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

Exemplos

O exemplo a seguir cria uma instância de geometry``GeometryCollection com valores Z no SRID 1 contendo uma instância de Point e uma instância de 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);  

Confira também

Dados espaciais (SQL Server)