将地理信息转换为 wkt 时 sql 中的 STAsText() 和 ToString() 有什么区别

What is the difference between STAsText() and ToString() in sql while converting geography to wkt

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) 和 (2) 给我相同的结果,即 LINESTRING (-132.36 50.657, -120.340 47.659)。 ToString() 和 STAsText() 有什么区别?

谢谢。

根据文档,ToString() returns 值 representation of a geography instance augmented with any Z (elevation) and M (measure) values carried by the instance.

然而,STAsTEXT() 函数 text will not contain any Z (elevation) or M (measure) values carried by the instance.

这些 SQL 地理功能似乎确实有些重叠。

STAsText(地理数据类型) 这将 return 文本将 包含实例携带的任何 Z(高程)或 M(测量)值

但是

ToString(地理数据类型) 这将 return 文本将包含实例携带的任何 Z(高程)或 M(测量)值

示例:

声明@g几何;
SET @g = geometry::STGeomFromText('POINT(1 2 3 4)', 0);

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

SELECT @g.STAsText() -- 结果POINT (1 2)