Contact us

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:

  1. MSQL supports only 2-dimensional spatial types.
  2. There is no single 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.


Spatial Coordinate Systems

There are two different kinds of spatial types available, depending on the coordinate system they rely on:

  • Geometric types - for representing spatial features in a planar coordinate system (i.e. x, y coordinates on an Euclidean plane).
  • Geographic types - for representing spatial features in a geodetic coordinate system (i.e. latitude/longitude coordinates on a sphere or an ellipse).

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 GEOMETRIES

Single 2D spatial objects in the Euclidean plane (point, line, polygon).

Name Description Example Example (WKT)
point A 2-D point in space point POINT (30 10)
line An arbitrary 2-D polyline, can be open or closed, can intersect with itself line LINESTRING (30 10, 10 30, 40 40)
polygon An arbitrary 2-D polygon, can have holes polygon POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))

GEOMETRY COLLECTIONS

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 mpoint 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 mline 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 mpolygon MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))

SINGLE GEOGRAPHIES

Single 2D spatial objects on a geodetic sphere (gpoint, gline, gpolygon).

Name Description Example Example (WKT)
gpoint A 2-D point in geodetic space gpoint POINT (30 10)
gline An arbitrary 2-D polyline, can be open or closed, can intersect with itself gline LINESTRING (30 10, 10 30, 40 40)
gpolygon An arbitrary 2-D polygon, can have holes gpolygon POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))

GEOGRAPHY COLLECTIONS

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 gmpoint 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 gmline 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 gmpolygon 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).


WKT Representation

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.


WKB Representation

This section is not yet completed.