geometry.STLength
spatial method STLength (instance.STLength(...))
What changes
- Input
- spatial instance (and arguments)
- Output or change
- float
- Return type
- SQL Server return type: float CLR return type: SqlDouble
Syntax at a glance
.STLength ( )
Work example
Use geometry.STLength to measure the length of curve elements.
For geometry record coordinate units. For geography check SRID units. Keep the geometry type and SRID in the review.
Check your work The segment from (0,0) to (3,4) is 5 planar coordinate units, not automatically 5 metres.
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'LINESTRING(0 0, 3 4)', 0);
SELECT @shape.STLength() AS length_in_coordinate_units,
@shape.STSrid AS source_srid,
@shape.STIsValid() AS source_is_valid;
Open Microsoft Learn for full syntax, permissions, and details for your version.