Returns the length measurement of the ST_Curve value. The result is measured in the units specified by the unit-name parameter.
SELECT NEW ST_LineString( 'LineString(1 0, 1 1, 2 1)' ).ST_Length()
The following example creates a circularstring representing a half-circle and uses ST_Length to find the length of the geometry, returning the value PI.
SELECT NEW ST_CircularString( 'CircularString( 0 0, 1 1, 2 0 )' ).ST_Length()
The following example creates a linestring representing a path from Halifax, NS to Waterloo, ON, Canada and uses ST_Length to find the length of the path in metres, returning the result 1361967.76789.
SELECT NEW ST_LineString( 'LineString( -63.573566 44.646244, -80.522372 43.465187 )', 4326 ) .ST_Length()
The following returns the lengths of the curves in the SpatialShapes table. The lengths are returned in Cartesian units.
SELECT ShapeID, TREAT( Shape AS ST_Curve ).ST_Length() FROM SpatialShapes WHERE Shape IS OF ( ST_Curve )
The following example creates a linestring and an example unit of measure (example_unit_halfmetre). The ST_Length method finds the length of the geometry in this unit of measure, returning the value 4.0.
BEGIN DECLARE @curve ST_Curve; CREATE SPATIAL UNIT OF MEASURE IF NOT EXISTS "example_unit_halfmetre" TYPE LINEAR CONVERT USING .5; SET @curve = NEW ST_LineString( 'LineString(1 0, 1 1, 2 1)' ) ; SELECT @curve.ST_Length('example_unit_halfmetre'); END
SQL/MM (ISO/IEC 13249-3: 2006) 7.1.2