4
DECLARE @geographyData geography; 
//Convert wkt to geography 

SET @geographyData = geography::Parse('LINESTRING(-132.360 50.657, -120.340 47.659)');


//Convert back to wkt from geography

(1) @geographyData.ToString();

(2) @geographyData.STAsText();

(1) and (2) giving me same result that is LINESTRING (-132.36 50.657, -120.340 47.659). What is the difference between ToString() and STAsText()?

Thanks.

Milan
  • 179
  • 1
  • 8

2 Answers2

5

STAsText (geography Data Type) this will return text will not contain any Z (elevation) or M (measure) values carried by the instance

but

ToString (geography Data Type) this will return text will contain any Z (elevation) or M (measure) values carried by the instance

Example:

DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POINT(1 2 3 4)', 0);

SELECT @g.ToString(); -- Result POINT (1 2 3 4)

SELECT @g.STAsText() -- Result POINT (1 2)

Ahmed Elbendary
  • 379
  • 5
  • 7
1

According to the docs, ToString() returns the value representation of a geography instance augmented with any Z (elevation) and M (measure) values carried by the instance.

However, the STAsTEXT() function text will not contain any Z (elevation) or M (measure) values carried by the instance.

There does seem to be some overlap in these SQL Geography functions.

Jacob H
  • 2,455
  • 1
  • 12
  • 29