Chapter 137. Analyzing Spatial Information

Table of Contents

Geometry Format Conversion Functions
Geometry Functions
General Geometry Functions
Point Functions
LineString Functions
MultiLineString Functions
Polygon Functions
MultiPolygon Functions
GeometryCollection Functions
Functions That Create New Geometries from Existing Ones
Geometry Functions That Produce New Geometries
Spatial Operators
Functions for Testing Spatial Relations Between Geometric Objects
Relations on Geometry Minimal Bounding Rectangles (MBRs)
Functions That Test Spatial Relationships Between Geometries

After populating spatial columns with values, you are ready to query and analyze them. MySQL provides a set of functions to perform various operations on spatial data. These functions can be grouped into four major categories according to the type of operation they perform:

Spatial analysis functions can be used in many contexts, such as:

Geometry Format Conversion Functions

MySQL supports the following functions for converting geometry values between internal format and either WKT or WKB format:

GeomFromText(wkt[,srid]) Converts a string value from its WKT representation into internal geometry format and returns the result. A number of type-specific functions are also supported, such as PointFromText() and LineFromText(); see GIS WKT Functions.
GeomFromWKB(wkb[,srid]) Converts a binary value from its WKB representation into internal geometry format and returns the result. A number of type-specific functions are also supported, such as PointFromWKB() and LineFromWKB(); see GIS WKB Functions.
AsText(g) Converts a value in internal geometry format to its WKT representation and returns the resulting string.
    mysql> SET @g = 'LineString(1 1,2 2,3 3)';
    mysql> SELECT AsText(GeomFromText(@g));
    +--------------------------+
    | AsText(GeomFromText(@G)) |
    +--------------------------+
    | LINESTRING(1 1,2 2,3 3)  |
    +--------------------------+
    
AsBinary(g) Converts a value in internal geometry format to its WKB representation and returns the resulting binary value.