Spatial types and functions
POINT, LINESTRING, POLYGON and the other spatial types, WKT and WKB, the ST_ and MBR functions, SPATIAL index definitions, and what is refused.
Raft DB keeps geometries in the servers' internal format (a 4-byte SRID, then the WKB) and sends them to clients as a binary GEOMETRY column. Only two dimensions are carried. Results were checked against MySQL 9.7 and MariaDB 11.4.
CREATE TABLE places (id INT PRIMARY KEY, loc POINT NOT NULL, area POLYGON, SPATIAL INDEX (loc));
INSERT INTO places VALUES (1, ST_GeomFromText('POINT(1 1)'), ST_GeomFromText('POLYGON((0 0,2 0,2 2,0 2,0 0))'));
SELECT ST_AsText(loc), ST_Area(area), ST_Contains(area, loc) FROM places;Types#
GEOMETRY, POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION. A value of another type is refused (MySQL 1416; MariaDB 1366, 4078). POINT SRID 4326 is MySQL's; the SRID is checked on insert (3643).
Functions#
- Make:
ST_GeomFromText,ST_PointFromText,ST_LineFromText,ST_PolyFromText,ST_MPointFromText,ST_MLineFromText,ST_MPolyFromText,ST_GeomCollFromText, the...FromWKBforms,Point,LineString,Polygon,MultiPoint,MultiLineString,MultiPolygon,GeometryCollection. - Read:
ST_AsText,ST_AsBinary,ST_X,ST_Y,ST_SRID,ST_GeometryType,ST_Dimension,ST_IsEmpty,ST_NumPoints,ST_StartPoint,ST_EndPoint,ST_PointN,ST_IsClosed,ST_NumGeometries,ST_GeometryN,ST_ExteriorRing,ST_NumInteriorRings,ST_InteriorRingN. - Measure and relate:
ST_Length,ST_Area,ST_Centroid,ST_Envelope,ST_Distance,ST_Contains,ST_Within,ST_Intersects,ST_Disjoint,ST_Equals,MBRContains,MBRWithin,MBRIntersects,MBRDisjoint,MBREquals,MBROverlaps,MBRTouches. - MariaDB only: the names without
ST_(GeomFromText,AsText,X,Y,GLength, ...).
Bad input: MySQL answers errors 3037, 3516, 3033, 3548; MariaDB answers NULL.
Indexes#
SPATIAL KEY | INDEX (in CREATE TABLE, ALTER TABLE, CREATE SPATIAL INDEX) is kept as a definition and listed by SHOW CREATE TABLE and SHOW INDEX; no structure is built and queries scan. The columns must be NOT NULL (1252). information_schema.GEOMETRY_COLUMNS (MariaDB) and ST_GEOMETRY_COLUMNS (MySQL) list the spatial columns.
Not supported#
ST_Buffer, ST_Union, ST_Intersection, ST_Difference, ST_SymDifference, ST_ConvexHull, ST_Simplify, ST_Transform, ST_Touches, ST_Crosses, ST_Overlaps, GeoJSON and geohash functions: error 1235. Every computation is planar: a geometry with SRID 4326 does not get geodetic results or lat-long axis order, and MySQL accepts only SRIDs 0 and 4326.