Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
SQL analytics endpoint in Microsoft Fabric
Warehouse in Microsoft Fabric
SQL database in Microsoft Fabric
A GeometryCollection is a collection of zero or more geometry or geography instances. A GeometryCollection can be empty.
For a GeometryCollection instance to be accepted, it must either be an empty GeometryCollection instance or all the instances comprising the GeometryCollection instance must be accepted instances. The following example shows accepted instances.
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)))';
The following example throws a System.FormatException
because the LinesString instance in the GeometryCollection instance is not accepted.
DECLARE @g geometry = 'GEOMETRYCOLLECTION(LINESTRING(1 1), POLYGON((-1 -1, -1 -5, -5 -5, -5 -1, -1 -1)))';
A GeometryCollection instance is valid when all instances that comprise the GeometryCollection instance are valid. The following shows three valid GeometryCollection instances and one instance that is not valid.
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
is not valid because the Polygon instance in the GeometryCollection instance is not valid.
For more information on accepted and valid instances, see Point, MultiPoint, LineString, MultiLineString, Polygon, and MultiPolygon.
The following example instantiates a geometry
GeometryCollection
with Z values in SRID 1 containing a Point
instance and a Polygon
instance.
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);
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayDocumentation
Point is a 0-dimensional object representing a single location and can contain Z (elevation) and M (measure) values in SQL Server spatial data.
Create, construct, and query geometry instances - SQL Server
Geometry instances represent data in a Euclidean (flat) coordinate system. Learn how to create, construct, and query geometry data in SQL Database Engine spatial data.
Polygon is a two-dimensional surface stored as a sequence of points defining an exterior bounding ring and zero or more interior rings, in SQL Server spatial data.