SQL Flow Field Guide

geometry::GeomFromGml

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

static constructor GeomFromGml (called as type::GeomFromGml(...))

What changes

Input
WKT, WKB, GML or coordinates and SRID
Output or change
spatial instance
Return type
SQL Server return type: geometry CLR return type: SqlGeometry

Syntax at a glance

GeomFromGml ( GML_input, SRID )

Work example

Use geometry.GeomFromGml to construct a spatial value from GML markup.

Validate namespace, coordinate order, and SRID before import. Keep the geometry type and SRID in the review.

Check your work The imported line spans 5 planar coordinate units. SRID 0 does not label them as metres.

Practice SQL

Open in SQL Flow

Open 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 @gml xml;
SET @gml = N'<LineString xmlns=''http://www.opengis.net/gml''><posList>0 0 3 4</posList></LineString>';
DECLARE @line geometry;
SET @line = geometry::GeomFromGml(@gml, 0);
SELECT @line.STAsText() AS imported_line,
       @line.STLength() AS length_in_coordinate_units,
       @line.STSrid AS result_srid,
       @line.STIsValid() AS result_is_valid;

Open Microsoft Learn for full syntax, permissions, and details for your version.