A Polygon is a two-dimensional surface stored as a sequence of points defining an exterior bounding ring and zero or more interior rings. A Polygon instance can be formed from a ring that has at least three distinct points. A Polygon instance can also be empty.
The exterior and any interior rings of a Polygon define its boundary. The space within the rings defines the interior of the Polygon. The interior rings of a Polygon can touch both themselves and each other at single tangent points, but if the interior rings of a Polygon cross, the instance is not valid.
The illustration below shows examples of Polygon instances.
As shown in the illustration:
The following example creates a simple geometry Polygon instance with a hole and SRID 10.
geometry
Polygon
DECLARE @g geometry; SET @g = geometry::STPolyFromText('POLYGON((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 1 2, 2 1, 1 1))', 10);
An instance that is not valid may be entered and converted to a valid geometry instance. In the following example of a Polygon, the interior and exterior rings overlap and the instance is not valid.
DECLARE @g geometry; SET @g = geometry::Parse('POLYGON((1 0, 0 1, 1 2, 2 1, 1 0), (2 0, 1 1, 2 2, 3 1, 2 0))');
In the following example, the invalid instance is made valid with MakeValid().
MakeValid()
SET @g = @g.MakeValid(); SELECT @g.ToString();
The geometry instance returned from the above example is a MultiPolygon.
MultiPolygon
MULTIPOLYGON (((2 0, 3 1, 2 2, 1.5 1.5, 2 1, 1.5 0.5, 2 0)), ((1 0, 1.5 0.5, 1 1, 1.5 1.5, 1 2, 0 1, 1 0)))