Spatial data types and operations which are supported in the MSQL are mostly based upon the Open Geospatial Consortium's OpenGIS - Simple Features Common Architecture and OpenGIS - Simple Features SQL specifications, although they don't follow the standard in every detail, but depart from it in several ways.
Two main differences of MSQL compared to the OpenGIS specification are:
GEOMETRY
type which can contain arbitrary spatial features.Spatial objects are strongly-typed, i.e. they are always of a specialized data type, (e.g. point
, linestring
, polygon
) and many spatial functions accept just the arguments of a specific type (e.g. ST_Length
accepts only (multi)linestring
objects).
A list of all the available spatial functions which deal with values of spatial types can be found here.
There are two different kinds of spatial types available, depending on the coordinate system they rely on:
x, y
coordinates on an Euclidean plane).The coordinates of all geometric objects are assumed to be in the Mireo World-Point coordinate system.
This is a coordinate system based on the Web Mercator projection (a.k.a. Google Web Mercator), but all the coordinates are scaled to fit into int32
data type.
The coordinates of all geographic objects are assumed to be in the WGS 84 coordinate system.
This is the World Geodetic System, the spatial reference system used in the GPS navigation system.
Conversions between geometric and geographic types are possible using ST_TOGEOG and ST_TOGEOM built-in functions. Conversions between the Mireo World-Point coordinates and the more common WGS 84 longitude-latitude coordinates are possible using the functions TO_LON, TO_LAT, TO_WPX, TO_WPY.
Single 2D spatial objects in the Euclidean plane (point
, line
, polygon
).
Name | Description | Example | Example (WKT) |
---|---|---|---|
point |
A 2-D point in space | ![]() |
POINT (30 10) |
line |
An arbitrary 2-D polyline, can be open or closed, can intersect with itself | ![]() |
LINESTRING (30 10, 10 30, 40 40) |
polygon |
An arbitrary 2-D polygon, can have holes | ![]() |
POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10)) |
Collections of 2D spatial objects in the Euclidean plane (mpoint
, mline
, mpolygon
).
Name | Description | Example | Example (WKT) |
---|---|---|---|
mpoint |
A set of any number of 2-D points, can be empty or contain one element | ![]() |
MULTIPOINT ((10 40), (40 30), (20 20), (30 10)) |
mline |
A set of any number of 2-D linestrings, can be empty or contain one element | ![]() |
MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10)) |
mpolygon |
A set of any number of 2-D polygons, can be empty or contain one element | ![]() |
MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5))) |
Single 2D spatial objects on a geodetic sphere (gpoint
, gline
, gpolygon
).
Name | Description | Example | Example (WKT) |
---|---|---|---|
gpoint |
A 2-D point in geodetic space | ![]() |
POINT (30 10) |
gline |
An arbitrary 2-D polyline, can be open or closed, can intersect with itself | ![]() |
LINESTRING (30 10, 10 30, 40 40) |
gpolygon |
An arbitrary 2-D polygon, can have holes | ![]() |
POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10)) |
Collections of 2D spatial objects on a geodetic sphere (gmpoint
, gmline
, gmpolygon
).
Name | Description | Example | Example (WKT) |
---|---|---|---|
gmpoint |
A set of any number of 2-D points, can be empty or contain one element | ![]() |
MULTIPOINT ((10 40), (40 30), (20 20), (30 10)) |
gmline |
A set of any number of 2-D linestrings, can be empty or contain one element | ![]() |
MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10)) |
gmpolygon |
A set of any number of 2-D polygons, can be empty or contain one element | ![]() |
MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5))) |
Neither geometric nor geographic objects can be stored in SpaceTime tables, as SpaceTime doesn't support storing arbitrary variable-length data.
Therefore, spatial objects should be constructed within a query from raw coordinates using the provided constructor functions (e.g. ST_POINT or ST_LINE).
The OpenGIS standard defines a Well-Known Text format for representing spatial objects as human-readable character strings. MSQL supports the WKT format by providing built-in functions for parsing and outputting WKT representations of its spatial objects. For a full list of these functions, see the documentation on spatial conversion functions.
The Well-Known Text format is defined according to the following rules:
Basic WKT building blocks:
<coord> ::= floating-point literal, e.g. '10' or '-3.5' or '1.3e6'
<coord-pair> ::= <coord> <coord>
<coord-sequence> ::= '(' <coord-pair> [',' <coord-pair>]* ')'
<point> ::= '(' <coord-pair> ')'
<point-sequence> ::= '(' <point> [',' <point>]* ')'
<polygon-rings> ::= '(' <coord-sequence> [',' <coord-sequence>]* ')'
WKT representations of spatial objects:
<point-WKT> ::= 'POINT' <point>
<linestring-WKT> ::= 'LINESTRING' ( <coord-sequence> | 'EMPTY' )
<polygon-WKT> ::= 'POLYGON' ( <polygon-rings> | 'EMPTY' )
<multipoint-WKT> ::= 'MULTIPOINT' ( <coord-sequence> | <point-sequence> | 'EMPTY' )
<multilinestring-WKT> ::= 'MULTILINESTRING' ( '(' <coord-sequence> [',' <coord-sequence>]* ')' | 'EMPTY' )
<multipolygon-WKT> ::= 'MULTIPOLYGON' ( '(' <polygon-rings> [',' <polygon-rings>]* ')' | 'EMPTY' )
Several examples of valid WKT strings:
'POINT (10 20)'
'LINESTRING (10 20, 30 30, 50 10)'
'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (3 3, 7 3, 5 5, 3 3))'
'MULTIPOINT (10 10, 30 30)'
'MULTILINESTRING ((0 0, 100 100), (110 110, 10 10))'
'MULTIPOLYGON EMPTY'
The WKT format is used to define MSQL spatial literals. It is also assumed as the default textual representation for casting spatial objects to and from character strings.
This section is not yet completed.