geometry.STGeometryN
spatial method STGeometryN (instance.STGeometryN(...))
What changes
- Input
- spatial instance (and arguments)
- Output or change
- geometry
- Return type
- SQL Server return type: geometry CLR return type: SqlGeometry
Syntax at a glance
.STGeometryN ( expression )
Work example
Use geometry.STGeometryN to read one member from a spatial collection.
Use a one-based index and retain a relational key when member identity matters. Keep the geometry type and SRID in the review.
Check your work STGeometryN is one-based. The second member is a line and the collection has 2 members.
Practice SQL
Open in SQL FlowOpen the SQL for a walkthrough. Run the example in SQL Server to check its result.
-- Planar geometry. SRID 0 coordinates here are synthetic units, not metres.
DECLARE @shape geometry;
SET @shape = geometry::STGeomFromText(N'GEOMETRYCOLLECTION(POINT(1 1), LINESTRING(0 0, 3 4))', 0);
SELECT @shape.STGeometryN(2).STAsText() AS second_collection_member, @shape.STNumGeometries() AS member_count,
@shape.STSrid AS source_srid,
@shape.STIsValid() AS source_is_valid;
Open Microsoft Learn for full syntax, permissions, and details for your version.