Compartilhar via


GeometryCollection

Aplica-se a:SQL ServerBanco de Dados SQL do AzureInstância Gerenciada de SQL do AzurePonto de extremidade de análise de SQL no Microsoft FabricWarehouse no Microsoft FabricBanco de dados SQL no Microsoft Fabric

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.

Example

O exemplo a seguir instancia a geometryGeometryCollection com valores Z no SRID 1 contendo 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);