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.

0

2 Answers 2

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)

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.