The ST_Geometry data type is a user-defined data type (UDT) that allows you to define columns that store spatial data.
ST_Geometry itself is an abstract, noninstantiated superclass. However, its subclasses can be instantiated. An instantiated data type is one that can be defined as a table column and have values of its type inserted into it.
Although you can define a column as type ST_Geometry, you do not insert ST_Geometry values into the column since it cannot be instantiated. Instead, you insert the subclass values.
The following chart demonstrates the hierarchy of the ST_Geometry data type and its subclasses. Be aware that ST_Curve, ST_Surface, ST_MultiCurve, and ST_MultiSurface are defined to be noninstantiated types. No constructors are defined for these types.
|
The ST_Geometry superclass and its subclasses |
Subclasses
ST_Geometry's subclasses are divided into two categories: the base geometry subclasses and the homogeneous collection subclasses. The base geometries include ST_Point, ST_LineString, and ST_Polygon, while the homogeneous collections include ST_MultiPoint, ST_MultiLineString, and ST_MultiPolygon. As the names imply, the homogeneous collections are collections of base geometries. In addition to sharing base geometry properties, homogeneous collections have some of their own properties.
Each subclass stores the type of geometry implied by its name; for instance, ST_MultiPoint stores multipoints. Each subclass has particular functions that can return information about the subclass. A summary of the subclasses, their descriptions, and example functions that can be used to get information about them are listed in the following table:
Subtype
|
Description
|
Functions used with the subtype
|
ST_Point
|
- A zero-dimensional geometry that occupies a single location in coordinate space
- Has a single x,y coordinate value, is always simple, and has a NULL boundary
- Used to define features such as oil wells, landmarks, and elevations
|
- ST_X—Returns a point's x-coordinate value as a double-precision number
- ST_Y—Returns a point's y-coordinate value as a double-precision number
- ST_Z—Returns a point's z-coordinate value as a double-precision number
- ST_M—Returns a point's m-coordinate value as a double-precision number
|
ST_LineString
|
- A one-dimensional object stored as a sequence of points defining a linear interpolated path
- ST_LineStrings have length.
- The ST_LineString is simple if it does not intersect its interior.
- The endpoints (the boundary) of a closed ST_LineString occupy the same point in space.
- An ST_LineString is a ring if it is both closed and simple.
- The endpoints normally form the boundary of an ST_LineString unless the ST_LineString is closed, in which case the boundary is NULL.
- The interior of an ST_LineString is the connected path that lies between the endpoints, unless it is closed, in which case the interior is continuous.
- ST_LineStrings are often used to define linear features such as roads, rivers, and power lines.
|
- ST_StartPoint—Returns the first point of a linestring
- ST_EndPoint—Returns the last point of a linestring
- ST_PointN—Takes a linestring and an index to an nth point and returns that point
- ST_Length—Returns a linestring's length as a double-precision number
- ST_NumPoints—Returns the number of points in a linestring's sequence as an integer
- ST_IsRing—Returns 1 (TRUE) if a linestring is a ring or 0 (FALSE) if it is not
- ST_IsClosed—Returns 1 (TRUE) if a linestring is closed or 0 (FALSE) if it is not
|
ST_Polygon
|
- A two-dimensional surface stored as a sequence of points defining its exterior bounding ring and zero or more interior rings
- ST_Polygon has area and is always simple.
- The exterior and any interior rings define the boundary of an ST_Polygon, and the space enclosed between the rings defines the ST_Polygon's interior.
- The rings of an ST_Polygon can intersect at a tangent point but never cross.
- Defines parcels of land, water bodies, and other features having spatial extent
|
- ST_Area—Returns a polygon's area as a double-precision number
- ST_ExteriorRing—Returns a polygon's exterior ring as a linestring
- ST_NumInteriorRing—Returns the number of interior rings a polygon contains
- ST_InteriorRingN—Takes a polygon and an index and returns the nth interior ring as a linestring
- ST_Centroid—Returns a point that is the center of the polygon's envelope
- ST_PointOnSurface—Returns a point that is guaranteed to be on the surface of the polygon
|
ST_MultiPoint
|
- A collection of ST_Points
- Has a dimension of 0
- An ST_MultiPoint is simple if none of its elements occupy the same coordinate space.
- The boundary of an ST_MultiPoint is NULL.
- Defines such things as aerial broadcast patterns and incidents of a disease outbreak
|
|
ST_MultiLineString
|
- A collection of ST_LineStrings
- ST_MultiLineStrings have length.
- ST_MultiLineStrings are simple if they only intersect at the endpoints of the ST_LineString elements.
- ST_MultiLineStrings are nonsimple if the interiors of the ST_LineString elements intersect.
- The boundary of an ST_MultiLineString is the nonintersected endpoints of the ST_LineString elements.
- The ST_MultiLineString is closed if all of its ST_LineString elements are closed.
- The boundary of an ST_MultiLineString is NULL if all the endpoints of all the elements are intersected.
- Used to define entities such as streams or road networks
|
- ST_Length—Returns the cumulative length of all the ST_LineString elements of a multilinestring as a double-precision number
- ST_IsClosed—Returns 1 (TRUE) if the multilinestring is closed and 0 (FALSE) if it is not
|
ST_MultiPolygon
|
- A collection of polygons
- ST_MultiPolygons have area.
- The boundary of an ST_MultiPolygon is the cumulative length of its elements' exterior and interior rings.
- The interior of an ST_MultiPolygon is defined as the cumulative interiors of its element ST_Polygons.
- The boundary of an ST_MultiPolygon's elements can only intersect at a tangent point.
- Define features such as a forest stratum or a noncontiguous parcel of land such as a Pacific island chain.
|
- ST_Area—Returns the cumulative ST_Area of a multipolygon's polygon elements as a double-precision number
- ST_Centroid—Returns a point that is the center of a multipolygon's envelope
- ST_PointOnSurface—Returns a point that is guaranteed to be normal to the surface of one of the multipolygon's polygon elements
|
ST_Geometry subtypesNote that each subclass inherits the properties of the ST_Geometry superclass but also has properties of its own. Functions that operate on the ST_Geometry data type accept any of the subclass data types. However, some functions have been defined at the subclass level and only accept certain subclasses. For example, the ST_GeometryN function only takes ST_MultiLinestring, ST_MultiPoint, or ST_MultiPolygon subtype values as input.
To discover the subclass of an ST_Geometry, you can use the ST_GeometryType function. The ST_GeometryType function takes an ST_Geometry and returns the instantiated subclass in the form of a character string. To find out how many base geometry elements are contained in a homogeneous collection, you can use the ST_NumGeometries function, which takes a homogeneous collection and returns the number of base geometry elements it contains.
11/18/2013