STCurveN (geography Data Type)

Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance SQL database in Microsoft Fabric

Returns the curve specified from a geography instance that is a LineString, CircularString, or CompoundCurve.

Syntax

  
.STCurveN( n )  

Arguments

n
Is an int expression between 1 and the number of curves in the geography instance.

Return Types

SQL Server return type: geography

CLR return type: SqlGeography

Exceptions

If n < 1 then an ArgumentOutOfRangeException is thrown.

Remarks

NULL is returned when the following criteria occurs.

Examples

A. Using STCurveN() on a CircularString

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)

B. Using STCurveN() on a CompoundCurve

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)

C. Using STCurveN() on a CompoundCurve Containing Three CircularStrings

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.

D. Testing for Validity Before Calling STCurve()

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

See Also

OGC Methods on Geography Instances