geometry::STPolyFromWKB
static constructor STPolyFromWKB (called as type::STPolyFromWKB(...))
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 OGC type: Polygon
Syntax at a glance
STPolyFromWKB ( 'WKB_polygon' , SRID )
Work example
Use geometry.STPolyFromWKB to construct a polygon from WKB bytes.
Validate ring structure and SRID before containment tests. Keep the geometry type and SRID in the review.
Check your work The WKB constructor returns a valid polygon with its hole. SRID is supplied 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, 10 0, 10 10, 0 10, 0 0),(2 2, 2 4, 4 4, 4 2, 2 2))', 0).STAsBinary();
DECLARE @result geometry;
SET @result = geometry::STPolyFromWKB(@payload, 0);
SELECT @result.STAsText() AS polygon_wkt,
@result.STSrid AS result_srid,
@result.STIsValid() AS result_is_valid;
Open Microsoft Learn for full syntax, permissions, and details for your version.