geometry::STGeomFromWKB
static constructor STGeomFromWKB (called as type::STGeomFromWKB(...))
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
STGeomFromWKB ( 'WKB_geometry' , SRID )
Work example
Use geometry.STGeomFromWKB to construct a spatial instance from WKB bytes.
Validate the binary source type and pair bytes with the intended SRID. Keep the geometry type and SRID in the review.
Check your work The round trip returns a square. WKB omits SQL Server SRID, which is passed separately.
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 @payload varbinary(max);
SET @payload = geometry::STGeomFromText(N'POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))', 0).STAsBinary();
DECLARE @result geometry;
SET @result = geometry::STGeomFromWKB(@payload, 0);
SELECT @result.STAsText() AS square_wkt,
@result.STSrid AS result_srid,
@result.STIsValid() AS result_is_valid;
Open Microsoft Learn for full syntax, permissions, and details for your version.