[GIS] How to generate 3d WKT FROM A Sql Server geometry or geography types

sql serverwell-known-text

If I have the point POINT (-75.45454 25.12345 1024 ) in a geometry or geography column in SQL Server, but render it with STAsText() I lose the Z dimension.

SELECT geography::STGeomFromText('POINT (-75.45454 25.12345 1024 )', 4326).STAsText() AS point

POINT (-75.45454 25.12345)

How do I get the full WKT? There is nothing listed in OGC Methods on Geography Instances.

Best Answer

The answer is AsTextZM (), which is listed on the Extended Methods on Geography.

WITH geo AS (
    SELECT geography::STGeomFromText('POINT (-75.45454 25.12345 1024 )', 4326) AS point)
SELECT 
    geo.point.AsTextZM() AS WTKFull,
    geo.point.STAsText() AS WTK2d
FROM geo