geometry.ToString
spatial method ToString (instance.ToString(...))
What changes
- Input
- spatial instance (and arguments)
- Output or change
- nvarchar(max)
- Return type
- SQL Server return type: nvarchar(max) CLR return type: SqlString
Syntax at a glance
.ToString ()
Work example
Use geometry.ToString to display a spatial instance as readable text.
Use explicit export when a contract needs WKT, WKB, GML, Z, or M. Keep the geometry type and SRID in the review.
Check your work ToString returns readable geometry text. Coordinates are planar values, not assumed metres.
Practice SQL
Open in SQL FlowOpen the SQL for a walkthrough. Run the example in SQL Server to check its result.
-- Planar geometry. SRID 0 coordinates here are synthetic units, not metres.
DECLARE @shape geometry;
SET @shape = geometry::STGeomFromText(N'POINT(3 4)', 0);
SELECT @shape.ToString() AS geometry_text,
@shape.STSrid AS source_srid,
@shape.STIsValid() AS source_is_valid;
Open Microsoft Learn for full syntax, permissions, and details for your version.