Returns the curve specified from a geography instance that is a LineString, CircularString, or CompoundCurve.
.STCurveN( n )
n
Is an int expression between 1 and the number of curves in the geography instance.
SQL Server return type: geography
CLR return type: SqlGeography
If n < 1 then an ArgumentOutOfRangeException is thrown.
NULL is returned when the following criteria occurs.
The geography instance is declared, but is not instantiated
The geography instance is empty
n exceeds the number of curves in the geography instance (See STNumCurves (geography Data Type)
The dimension for the geography instance does not equal (See STDimension (geography Data Type)
The following example returns the second curve in a CircularString instance:
DECLARE @g geography = 'CIRCULARSTRING(-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653)';
SELECT @g.STCurveN(2).ToString();
The example returns.
CIRCULARSTRING (-122.348 47.658, -122.358 47.658, -122.358 47.653)
The following example returns the second curve in a CompoundCurve instance:
DECLARE @g geography = 'COMPOUNDCURVE(CIRCULARSTRING(-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))';
SELECT @g.STCurveN(2).ToString();
The example returns.
CIRCULARSTRING (-122.348 47.658, -122.358 47.658, -122.358 47.653)
The following example uses a CompoundCurve instance that combines three separate CircularString instances into the same curve sequence as the previous example:
DECLARE @g geography = 'COMPOUNDCURVE (CIRCULARSTRING (-122.358 47.653, -122.348 47.649, -122.348 47.658), CIRCULARSTRING(-122.348 47.658, -122.358 47.658, -122.358 47.653))';
SELECT @g.STCurveN(2).ToString();
The example returns.
CIRCULARSTRING (-122.348 47.658, -122.358 47.658, -122.358 47.653)
STCurveN()
returns the same results regardless of Well-Known Text (WKT) format that is used.
The following example shows how to make sure that n is valid before you call the STCurveN() method:
DECLARE @g geography;
DECLARE @n int;
SET @n = 2;
SET @g = geography::Parse('LINESTRING(-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653)');
IF @n >= 1 AND @n <= @g.STNumCurves()
BEGIN
SELECT @g.STCurveN(@n).ToString();
END