Querying Properties and Behaviors of geometry Instances

All geometry instances have a number of properties that can be retrieved through methods that SQL Server provides. The following topics define the properties and behaviors of geometry types, and the methods for querying each one.

Number of Points

All nonempty geometry instances are comprised of points. These points represent the X- and Y-coordinates of the plane on which the geometries are drawn. geometry provides numerous built-in methods for querying the points of an instance.

To return the number of points that comprise an instance

To return a specific point in an instance

To return an arbitrary point that lies on an instance

To return the start point of an instance

To return the end point of an instance

To return the X-coordinate of a Point instance

To return the Y-coordinate of a Point instance

STY

To return the geometric center point of a Polygon or MultiPolygon instance

Dimension

A nonempty geometry instance can be 0-, 1-, or 2-dimensional. Zero-dimensional geometries, such as Point and MultiPoint, have no length or area. One-dimensional objects, such as LineString and MultiLineString, have length. Two-dimensional instances, such as Polygon and MultiPolygon, have area and length. Empty instances will report a dimension of -1, and a GeometryCollection will report an area dependent on the types of its contents.

To return the dimension of an instance

To return the length of an instance

To return the area of an instance

Empty

An emptygeometry instance does not have any points. The length of empty LineString and MultiLineString instances is zero. The area of empty Polygon and MultiPolygon instances is 0.

To determine if an instance is empty

Simple

For a geometry of the instance to be simple, it must meet both of these requirements:

  • Each figure of the instance must not intersect itself, except at its endpoints.

  • No two figures of the instance can intersect each other at a point that is not in both of their boundaries.

Note

Empty geometries are always simple.

To determine if an instance is simple

Boundary, Interior, and Exterior

The interior of a geometry instance is the space occupied by the instance, and the exterior is the space not occupied it.

Boundary is defined by the OGC as follows:

  • Point and MultiPoint instances do not have a boundary.

  • LineString and MultiLineString boundaries are formed by the start points and end points, removing those that occur an even number of times.

DECLARE @g geometry;
SET @g = geometry::Parse('MULTILINESTRING((0 1, 0 0, 1 0, 0 1), (1 1, 1 0))');
SELECT @g.STBoundary().ToString();

The boundary of a Polygon or MultiPolygon instance is the set of its rings.

DECLARE @g geometry;
SET @g = geometry::Parse('POLYGON((0 0, 3 0, 3 3, 0 3, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))');
SELECT @g.STBoundary().ToString();

To return the boundary of an instance

STBoundary

Envelope

The envelope of a geometry instance, also known as the bounding box, is the axis-aligned rectangle formed by the minimum and maximum (X,Y) coordinates of the instance.

To return the envelope of an instance

STEnvelope

Closure

A closedgeometry instance is a figure whose start points and end points are the same. Polygon instances are considered closed. Point instances are not closed.

A ring is a simple, closed LineString instance.

To determine if an instance is closed

STIsClosed

To determine if an instance is a ring

STIsRing

To return the exterior ring of a Polygon instance

STExteriorRing

To return the number of interior rings in a Polygon

STNumInteriorRing

To return a specified interior ring of a Polygon

STInteriorRingN

Spatial Reference ID (SRID)

The spatial reference ID (SRID) is an identifier specifying which coordinate system the geometry instance is represented in. Two instances with different SRIDs are incomparable.

To set or return the SRID of an instance

STSrid

This property can be modified.