Go to the first, previous, next, last section, table of contents.


9 Spatial Extensions in MySQL

9.1 Introduction

In release 4.1 MySQL introduces spatial extensions, which allow generating, storing and analysing of geographic features.

9.1.1 Geographic Features

A geographic feature is anything in the world that has a location.

A feature can be:

You can also find documents which use term geospatial feature to refer to geographic features.

Geometry is another word that denotes a geographic feature. The original meaning of the word geometry denotes a branch of mathematics. Another meaning that comes from cartography, referring to the geometric features that cartographers use to map the world.

We will mean the same thing using all these terms, a geographic feature, or a geospatial feature, or a feature, or a geometry, with geometry as the most used in this documentation.

Let's define a geometry as a point or an aggregate of points representing anything in the world that has a location.

9.1.2 Approach

MySQL implements spatial extensions following OpenGIS specifications.

The OpenGIS Consortium (OGC), is an international consortium of more than 250 companies, agencies, universities participating in the development of publicly available conceptual solutions that can be useful with all kinds of applications that manage spatial data. See http://www.opengis.org/.

In 1997, the OpenGIS Consortium published the OpenGIS (r) Simple Features Specifications For SQL, which proposes several conceptual ways for extending an SQL RDBMS to support spatial data. MySQL implements a subset of the SQL with Geometry Types environment proposed by OGC. This term refers to an SQL environment that has been extended with a set of geometry types. A geometry-valued SQL column is implemented as a column of a geometry type. The specifications describe a set of SQL geometry types, as well as functions on those types to create and analyse geometry values.

9.2 OpenGIS Geometry Model

The set of geometry types, proposed by OGC's SQL with Geometry Types environment, is based of OpenGIS Geometry Model. In this model, each geometric object:

9.2.1 Geometry Class Hierarchy

Geometry is the base class. It's an abstract (non-instantiable) class. The instantiable subclasses of Geometry are restricted to zero, one, and two-dimensional geometric objects that exist in two-dimensional coordinate space. All instantiable geometry classes are defined so that valid instances of a geometry class are topologically closed (i.e. all defined geometries include their boundary).

The base Geometry class has subclasses for Point, Curve, Surface and GeometryCollection.

Curve stands for 1-dimensional objects, and has subclass LineString, with sub-subclasses Line and LinearRing.

Surface is designed for two-dimensional objects and has subclass Polygon.

GeometryCollection has specialised 0, 1 and two-dimensional collection classes named MultiPoint, MultiLineString and MultiPolygon for modelling geometries corresponding to collections of Points, LineStrings and Polygons respectively. MultiCurve and MultiSurface are introduced as abstract superclasses that generalise the collection interfaces to handle Curves and Surfaces.

Geometry, Curve, Surface, MultiCurve and MultiSurface are defined as non-instantiable classes, it is not possible to create an object of these classes. They define a common set of methods for its subclasses and included for the reason of extensibility.

Point, LineString, Polygon, GeometryCollection, MultiPoint, MultiLineString, MultiPolygon are instantiable classes (marked bold in the hierarchy tree).

9.2.2 Class Geometry

Geometry is the root class of the hierarchy. Each geometry is described by a number of its properties. Particular subclasses of the root class Geometry have their own specific properties. Properties, which are common for all geometry subclasses, are described in the list below. Geometry is a non-instantiable class.

9.2.3 Geometry properties

9.2.4 Class Point

A Point is a geometry that represents a single location in coordinate space.

9.2.5 Point examples

9.2.6 Point properties

9.2.7 Class Curve

A Curve is a one-dimensional geometry, usually represented by a sequence of points. Particular subclasses of Curve specify the form of the interpolation between points. Curve is a non-instantiable class.

9.2.8 Curve properties

9.2.9 Class LineString

A LineString is a Curve with linear interpolation between points.

9.2.10 LineString examples

9.2.11 LineString properties

9.2.12 Class Surface

A Surface is a two-dimensional geometric object.

9.2.13 Surface properties

The only instantiable subclass of Surface defined in OpenGIS specification, is Polygon.

9.2.14 Class Polygon

A Polygon is a planar Surface representing a multisided geometry, defined by one exterior boundary and zero or more interior boundaries. Each interior boundary defines a hole in the Polygon.

9.2.15 Polygon examples

The assertions for polygons (the rules that define valid polygons) are:

  1. The boundary of a Polygon consists of a set of LinearRings (i.e. LineStrings that are both simple and closed) that make up its exterior and interior boundaries.
  2. No two rings in the boundary cross, the rings in the boundary of a Polygon may intersect at a Point but only as a tangent.
  3. A Polygon may not have cut lines, spikes or punctures.
  4. The Interior of every Polygon is a connected point set.
  5. The Exterior of a Polygon with one or more holes is not connected. Each hole defines a connected component of the Exterior.

In the above assertions, polygons are simple geometries.

9.2.16 Class GeometryCollection

A GeometryCollection is a geometry that is a collection of one or more geometries of any class.

All the elements in a GeometryCollection must be in the same Spatial Reference (i.e. in the same coordinate system). GeometryCollection places no other constraints on its elements.

Subclasses of GeometryCollection described below may restrict membership based on:

9.2.17 Class MultiPoint

A MultiPoint is a collection whose elements are restricted to Points. The points are not connected or ordered in any way.

9.2.18 MultiPoint examples

9.2.19 MultiPoint properties

9.2.20 Class MultiCurve

A MultiCurve is a geometry collection whose elements are Curves. MultiCurve is a non-instantiable class.

9.2.21 MultiCurve properties

9.2.22 Class MultiLineString

A MultiLineString is a MultiCurve whose elements are LineStrings.

9.2.23 MultiLineString examples

9.2.24 Class MultiSurface

A MultiSurface is a geometric collection whose elements are surfaces. MultiSurface is a non-instantiable class.

9.2.25 MultiSurface assertions

  1. The interiors of any two surfaces in a MultiSurface may not intersect.
  2. The boundaries of any two elements in a MultiSurface may intersect at most at a finite number of points.

The only instantiable subclass of MultiSurface is MultiPolygon.

9.2.26 Class MultiPolygon

A MultiPolygon is a MultiSurface whose elements are Polygons.

9.2.27 MultiPolygon examples

9.2.28 The assertions for MultiPolygons are:

  1. The interiors of two Polygons that are elements of a MultiPolygon may not intersect.
  2. The Boundaries of any two Polygons that are elements of a MultiPolygon may not cross and may touch at only a finite number of points. (Note that crossing is already forbidden by the first assertion.)
  3. A MultiPolygon may not have cut lines, spikes or punctures; a MultiPolygon is a Regular, Closed point set.
  4. The interior of a MultiPolygon with more than one Polygon is not connected, the number of connected components of the interior of a MultiPolygon is equal to the number of Polygons in the MultiPolygon.

9.2.29 MultiPolygon properties

9.3 Supported Spatial Data Formats

This section describes the standard spatial data formats that are used to store geometry objects.

They are:

9.3.1 Well-Known Text (WKT) Representation

The Well-Known Text (WKT) representation of Geometry is designed to exchange geometry data in ASCII form.

9.3.1.1 WKT Examples

Examples of WKT representations of geometry objects are:

POINT(10 10)
A Point.
LINESTRING(10 10, 20 20, 30 40)
A LineString with three points.
POLYGON((10 10, 10 20, 20 20, 20 15, 10 10))
A Polygon with one exterior ring and zero interior rings.
MULTIPOINT(10 10, 20 20)
A MultiPoint with two Points.
MULTILINESTRING((10 10, 20 20), (15 15, 30 15))
A MultiLineString with two LineStrings.
MULTIPOLYGON(((10 10, 10 20, 20 20, 20 15, 10 10)), ((60 60, 70 7, 80 60, 60 60 )))
A MultiPolygon with two Polygons.
GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))
A GeometryCollection consisting of two Points and one LineString.

9.3.1.2 Bachus-Naur Forms of WKT

The text representation of the implemented instantiable geometric types conforms to this grammar:

<Geometry Tagged Text> :=
            <Point Tagged Text>
          | <LineString Tagged Text>
          | <Polygon Tagged Text>
          | <MultiPoint Tagged Text>
          | <MultiLineString Tagged Text>
          | <MultiPolygon Tagged Text>
          | <GeometryCollection Tagged Text>
<Point Tagged Text> := POINT <Point Text>
<LineString Tagged Text> := LINESTRING <LineString Text>
<Polygon Tagged Text> := POLYGON <Polygon Text>
<MultiPoint Tagged Text> := MULTIPOINT <Multipoint Text>
<MultiLineString Tagged Text> := MULTILINESTRING <MultiLineString Text>
<MultiPolygon Tagged Text> := MULTIPOLYGON <MultiPolygon Text>
<GeometryCollection Tagged Text> := GEOMETRYCOLLECTION <GeometryCollection Text>
<Point Text> := EMPTY | ( <Point> )
<Point> := <x> <y>
<x> := double precision literal
<y> := double precision literal
<LineString Text> :=         EMPTY | ( <Point >  {, <Point > }* )
<Polygon Text> :=            EMPTY | ( <LineString Text >  {, < LineString Text > }*)
<Multipoint Text> :=         EMPTY | ( <Point Text >  {, <Point Text > }* )
<MultiLineString Text> :=    EMPTY | ( <LineString Text >  {, < LineString Text > }* )
<MultiPolygon Text> :=       EMPTY | ( < Polygon Text >  {, < Polygon Text > }* )
<GeometryCollection Text> := EMPTY | ( <Geometry Tagged Text> {, <Geometry Tagged Text> }* )

9.3.2 Well-Known Binary (WKB) Representation

Well-Known Binary (WKB) representation is defined by the OpenGIS specifications. It's also defined in the ISO "SQL/MM Part 3: Spatial" standard.

WKB is used to exchange geometry data as binary streams represented by BLOB values containing geometic information, according to the structures described below.

WKB uses the following basic type definitions:

9.3.2.1 WKB Basic Types

// byte   : 8-bit unsigned integer (1 byte)
// uint32 : 32-bit unsigned integer (4 bytes)
// double : double precision number (8 bytes)
enum wkbGeometryType
{
	wkbPoint              = 1,
	wkbLineString         = 2,
	wkbPolygon            = 3,
	wkbMultiPoint         = 4,
	wkbMultiLineString    = 5,
	wkbMultiPolygon       = 6,
	wkbGeometryCollection = 7
}
enum wkbByteOrder
{
	wkbXDR = 0,    // Big Endian
	wkbNDR = 1     // Little Endian
}

9.3.2.2 WKB Building Blocks

// Building Blocks : Point, LinearRing
Point
{
	double  x;
	double  y;
}
LinearRing
{
	uint32  numPoints;
	Point   points[numPoints];
}

9.3.2.3 WKB Representation of Geometry Values

WKBPoint
{
	byte    byteOrder;
	uint32  wkbType;     // 1
	Point   point;
}
WKBLineString
{
	byte    byteOrder;
	uint32  wkbType;     // 2
	uint32  numPoints;
	Point   points[numPoints];
}
WKBPolygon
{
	byte       byteOrder;
	uint32     wkbType;  // 3
	uint32     numRings;
	LinearRing rings[numRings];
}
WKBMultiPoint
{
	byte       byteOrder;
	uint32     wkbType;  // 4
	uint32     num_wkbPoints;
	WKBPoint   WKBPoints[num_wkbPoints];
}
WKBMultiLineString
{
	byte          byteOrder;
	uint32        wkbType;    // 5
	uint32        num_wkbLineStrings;
	WKBLineString WKBLineStrings[num_wkbLineStrings];
}
wkbMultiPolygon
{
	byte       byteOrder;
	uint32     wkbType;    // 6
	uint32     num_wkbPolygons;
	WKBPolygon wkbPolygons[num_wkbPolygons];
}
WKBGeometry
{
	union
	{
		WKBPoint		point;
		WKBLineString		linestring;
		WKBPolygon		polygon;
		WKBGeometryCollection	collection;
		WKBMultiPoint		mpoint;
		WKBMultiLineString	mlinestring;
		WKBMultiPolygon		mpolygon;
	}
}
WKBGeometryCollection
{
	byte		byte_order;
	uint32		wkbType;    // 7
	uint32		num_wkbGeometries;
	WKBGeometry	wkbGeometries[num_wkbGeometries];
}

9.3.2.4 WKB Examples

A WKB which corresponds to POINT(1,1) looks like this sequence of 21 bytes:

0101000000000000000000F03F000000000000F03F

Where, consequently,

Byte order : 01
WKB type   : 01000000
X          : 000000000000F03F
Y          : 000000000000F03F

9.4 Creating a Spatially Enabled MySQL Database

9.4.1 MySQL Spatial Data Types

MySQL provides a hierarchy of datatypes, corresponding to the OpenGIS Geometry Model.

The GEOMETRY type can store geometries of any type, other types restrict their values to a partilcular geometry type. GEOMETRYCOLLECTION can store a collection of objects of any type, other collection types restrict the type of collection members to a particular geometry type.

9.4.2 Creating Spatial Values

9.4.2.1 Creating a Geometry Using Its WKT

MySQL provides a number of function which take a Well-Known Text representation and, optionally, a spatial reference system identifier as input parameters, and return the corresponding geometry.

GeomFromText() accepts a WKT of any geometry type as its first argument.

For construction of geometry values restricted to a particular type, an implementation also provides a type-specific construction function for each geometry type.

9.4.2.2 Functions To Create a Geometry Using Its WKT

GeomFromText(wkt,srid)
GeometryFromText(wkt,srid)
Constructs a geometry of any type using its WKT representation and SRID.
PointFromText(wkt,srid)
Constructs a POINT using its WKT representation and SRID.
LineFromText(wkt,srid)
LineStringFromText(wkt,srid)
Constructs a LINESTRING using its WKT representation and SRID.
PolyFromText(wkt,srid)
PolygonFromText(wkt,srid)
Constructs a POLYGON using its WKT representation and SRID.
MPointFromText(wkt,srid)
MultiPointFromText(wkt,srid)
Constructs a MULTIPOINT using its WKT representation and SRID.
MLineFromText(wkt,srid)
MultiLineStringFromText(wkt,srid)
Constructs a MULTILINESTRING using its WKT representation and SRID.
MPolyFromText(wkt,srid)
MultiPolygonFromText(wkt,srid)
Constructs a MULTIPOLYGON using its WKT representation and SRID.
GeomCollFromText(wkt,srid)
Constructs a GEOMETRYCOLLECTION using its WKT representation and SRID.

As an optional feature, an implementation may also support building of Polygon or MultiPolygon values, given an arbitrary collection of possibly intersecting rings or closed LineString values. Implementations that support this feature should include the following functions (Note: MySQL does not yet implement these):

BdPolyFromText(multiLineStringTaggedText String, SRID Integer):Polygon
Constructs a Polygon given an arbitrary collection of closed linestrings as a MultiLineString text representation.
BdMPolyFromText(multiLineStringTaggedText String, SRID Integer):MultiPolygon
Constructs a MultiPolygon given an arbitrary collection of closed Linestrings as a MultiLineString text representation.

9.4.2.3 Creating a Geometry Using Its WKB

MySQL provides a set of functions which take a BLOB containing Well-Known Binary representation and, optionally, a spatial reference system identifier (SRID) as their input parameters, and return the corresponding geometry.

GeomFromWKB can accept a WKB of any geometry type as its first argument. For construction of geometry values restricted to a particular type, an implementation also provides a specific construction function for each type of geometry as described in the list above.

9.4.2.4 Functions To Create a Geometry Using Its WKB

GeomFromWKB(wkb,srid)
GeometryFromWKB(wkt,srid)
Constructs a geometry of any type using its WKB representation and SRID.
PointFromWKB(wkb,srid)
Constructs a POINT using its WKB representation and SRID.
LineFromWKB(wkb,srid)
LineStringFromWKB(wkb,srid)
Constructs a LINESTRING using its WKB representation and SRID.
PolyFromWKB(wkb,srid)
PolygonFromWKB(wkb,srid)
Constructs a POLYGON using its WKB representation and SRID.
MPointFromWKB(wkb,srid)
MultiPointFromWKB(wkb,srid)
Constructs a MULTIPOINT using its WKB representation and SRID.
MLineFromWKB(wkb,srid)
MultiLineStringFromWKB(wkb,srid)
Constructs a MULTILINESTRING using its WKB representation and SRID.
MPolyFromWKB(wkb,srid)
MultiPolygonFromWKB(wkb,srid)
Constructs a MULTIPOLYGON using its WKB representation and SRID.
GeomCollFromWKB(wkb,srid)
Constructs a GEOMETRYCOLLECTION using its WKB representation and SRID.

As an optional feature, an implementation may also support the building' of Polygon or MultiPolygon values given an arbitrary collection of possibly intersecting rings or closed LineString values. Implementations that support this feature should include the following functions (Note: MySQL does not yet implement these):

BdPolyFromWKB(WKBMultiLineString Binary,SRID Integer): Polygon
Constructs a Polygon given an arbitrary collection of closed linestrings as a MultiLineString binary representation.
BdMPolyFromWKB(WKBMultiLineString Binary, SRID Integer):MultiPolygon
Constructs a MultiPolygon given an arbitrary collection of closed linestrings as a MultiLineString binary representation.

9.4.2.5 Creating a Geometry Value Using MySQL-Specific Functions

Note: the functions listed in this section are not yet implemented in the current version.

MySQL provides a set of useful functions for creating geometry WKB representations. The functions described in this section are MySQL extensions to the OpenGIS specifications. The results of these functions are BLOBs containing geometry WKB representations. The results of these functions can be substituted as first argument for GeomFromWKB() function family.

Point(x,y)
Constructs a WKBPoint using its coordinates.
MultiPoint(WKBPoint,WKBPoint,...,WKBPoint)
Constructs a WKBMultiPoint using WKBPoints. When any argument is not WKBPoint, the return value is NULL.
LineString(WKBPoint,WKBPoint,...,WKBPoint)
Constructs a WKBLineString from a number of WKBPoints. When any argument is not WKBPoint, the return value is NULL. When the number of WKBPoints is less than two the return value is NULL.
MultiLineString(WKBLineString,WKBLineString,...,WKBLineString)
Constructs a WKBMultiLineString using using WKBLineStrings. When any argument is not WKBLineString, the return value is NULL.
Polygon(WKBLineString,WKBLineString,...,WKBLineString)
Constructs a Polygon from a number of WKBLineStrings. When any argument is not representing WKB of a LinearRing (i.e. not closed and simple LineString) the return value is NULL.
MultiPolygon(WKBPolygon,WKBPolygon,...,WKBPolygon)
Constructs a WKBMultiPolygon from a set of WKBPolygons. When any argument is not a WKBPolygon, the rerurn value is NULL.
GeometryCollection(WKBGeometry,WKBGeometry,..,WKBGeometry)
Constucts a GeometryCollection. When any argument is not a well-formed WKB representation of a geometry, the return value is NULL.

9.4.3 Creating Spatial Columns

MySQL provides a standard way of creating spatial columns for geometry types.

CREATE TABLE
Use the CREATE TABLE statement to create a table with a spatial column:
mysql> CREATE TABLE g1 (p1 GEOMETRY);
Query OK, 0 rows affected (0.02 sec)
mysql>
ALTER TABLE
Use the ALTER TABLE statement to add a spatial column to an existing table:
mysql> ALTER TABLE g1 ADD p2 POINT;
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0
mysql>

9.4.4 Populating Spatial Columns

After you have created spatial columns, you can populate them with your spatial data.

To populate spatially enabled columns, MySQL supports two spatial formats (described previously), Well Known Text (WKT) and Well-Known Binary (WKB) representation.

9.4.4.1 Examples Of Using WKT Functions

INSERT INTO geom VALUES (GeomFromText('POINT(1 1)'))
INSERT INTO geom VALUES (GeomFromText('LINESTRING(0 0,1 1,2 2)'))
INSERT INTO geom VALUES (GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))'))
INSERT INTO geom VALUES (GeomFromText('GEOMETRYCOLLECTION(POINT(1 1),LINESTRING(0 0,1 1,2 2,3 3,4 4))'))
INSERT INTO geom VALUES (PointFromText('POINT(1 1)'))
INSERT INTO geom VALUES (LineStringFromText('LINESTRING(0 0,1 1,2 2)'))
INSERT INTO geom VALUES (PolygomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))'))
INSERT INTO geom VALUES (GeomCollFromText('GEOMETRYCOLLECTION(POINT(1 1),LINESTRING(0 0,1 1,2 2,3 3,4 4))'))

Note, a client application program which wants to use WKB representation of geometry values, is responsible for sending correctly formed WKB in queries to server.

Inserting a Point(1,1) with binary literal syntax:
INSERT INTO geom VALUES (GeomFromWKB(0x0101000000000000000000F03F000000000000F03F));
An ODBC applications can send a WKB representation, binding it as an argument of BLOB type:
INSERT INTO geom VALUES (GeomFromWKB(?));
Inserting Point(1,1) using the result of mysql_escape_string() in libmysqlclient applications.
INSERT INTO geom VALUES (GeomFromWKB('\0\0\0\0\0\0\0\0\0ð?\0\0\0\0\0\0ð?'));

9.4.5 Fetching Spatial Data

Geometry values, previously stored in a table, can be fetched in either WKT or WKB representation.

9.4.5.1 Fetching Spatial Data Using WKT Representation

The AsText() function provides textual access to geometry values by converting them into a WKT string.

mysql> SELECT AsText(p1) FROM g1;
+-------------------------+
| AsText(p1)              |
+-------------------------+
| POINT(1 1)              |
| LINESTRING(0 0,1 1,2 2) |
+-------------------------+
2 rows in set (0.00 sec)

9.4.5.2 Fetching Spatial Data Using WKB Representation

The AsBinary() and AsWKB() functions provide binary access to geometry values by converting them into a BLOB containing WKB.

SELECT AsBinary(g) FROM geom;
SELECT AsWKB(g) FROM geom;

AsBinary() and AsWKB() return a BLOB with a geometry in its WKB representation.

9.5 Analysing Spatial Information

After populating spatial columns with values, you are ready to query and analyse them. Spatial analysis can be performed using spatial functions in:

MySQL provides a set of functions to perform various operations on spatial data. These functions can be labeled into four major groups according to the type of operation they perform:

9.5.1 Functions To Convert Geometries Between Different Formats

As discussed (see section 9.4.1 MySQL Spatial Data Types, see section 9.4.4 Populating Spatial Columns), MySQL understands Well-Known Text (WKT) and Well-Known Binary (WKB) geometry representations through support of these functions:

GeomFromWKT(string wkt [,integer srid]): geometry
Converts WKT representation into internal geometry format. A number of type-specific functions are also supported.
GeomFromWKB(binary wkb [,integer srid]): geometry
Converts WKB representation into internal geometry format A number of type-specific functions are also supported.
AsWKT(geometry g): string
Converts internal geometry format into WKT representation.
AsWKB(geometry g): binary
Converts internal geometry format into WKB representation.
mysql> SELECT AsText(GeomFromText('LineString(1 1,2 2,3 3)'));
+-------------------------------------------------+
| AsText(GeomFromText('LineString(1 1,2 2,3 3)')) |
+-------------------------------------------------+
| LINESTRING(1 1,2 2,3 3)                         |
+-------------------------------------------------+

9.5.2 Functions To Analyse Geometry Properties

Functions that belong to this group take a geometry value as their argument and return some quantitive or qualitive property of this geometry. Some functions restrict their argument type.

9.5.2.1 Basic Functions To Analyse Geometry Properties

These functions don't restrict their argument and accept a geometry of any type.

GeometryType(geometry g):string
Returns as string the name of the geometry subtype of which this geometry instance is a member.
mysql> SELECT GeometryType(GeomFromText('POINT(1 1)'));
+------------------------------------------+
| GeometryType(GeomFromText('POINT(1 1)')) |
+------------------------------------------+
| POINT                                    |
+------------------------------------------+
Dimension(geometry g):integer
The inherent dimension of this Geometry object, which can be -1, 0, 1 or 2.
mysql> SELECT Dimension(GeomFromText('LineString(1 1,2 2)'));
+------------------------------------------------+
| Dimension(GeomFromText('LineString(1 1,2 2)')) |
+------------------------------------------------+
|                                              1 |
+------------------------------------------------+
SRID(geometry g):integer
Returns the Spatial Reference System ID for this geometry.
mysql> SELECT SRID(GeomFromText('LineString(1 1,2 2)',101));
+-----------------------------------------------+
| SRID(GeomFromText('LineString(1 1,2 2)',101)) |
+-----------------------------------------------+
|                                           101 |
+-----------------------------------------------+
Envelope(geometry g):geometry
The Minimum Bounding Rectangle (MBR) for this geometry, returned as a polygon. The polygon is defined by the corner points of the bounding box:
POLYGON((MINX MINY, MAXX MINY, MAXX MAXY, MINX MAXY, MINX MINY))
mysql> SELECT AsText(Envelope(GeomFromText('LineString(1 1,2 2)',101)));
+-----------------------------------------------------------+
| AsText(Envelope(GeomFromText('LineString(1 1,2 2)',101))) |
+-----------------------------------------------------------+
| POLYGON((1 1,2 1,2 2,1 2,1 1))                            |
+-----------------------------------------------------------+

Note: MySQL does not yet implement the following functions:

Boundary(g:Geometry):Geometry
Returns the closure of the combinatorial boundary of this Geometry.
IsEmpty(geometry g):Integer
Returns 1 (TRUE) if this Geometry is the empty geometry. If true, then this Geometry represents the empty point set.
IsSimple(geometry g):Integer
Returns 1 (TRUE) if this Geometry has no anomalous geometric points, such as self intersection or self tangency. The description of each instantiable geometric class includes the specific conditions that cause an instance of that class to be classified as not simple.

9.5.2.2 Functions To Analyse Point Properties

X(point p):Double
The x-coordinate value for this point.
mysql> SELECT X(GeomFromText('Point(56.7 53.34)',101));
+------------------------------------------+
| X(GeomFromText('Point(56.7 53.34)',101)) |
+------------------------------------------+
|                                     56.7 |
+------------------------------------------+
Y(point p):Double
The y-coordinate value for this point
mysql> SELECT Y(GeomFromText('Point(56.7 53.34)',101));
+------------------------------------------+
| Y(GeomFromText('Point(56.7 53.34)',101)) |
+------------------------------------------+
|                                    53.34 |
+------------------------------------------+

9.5.2.3 Functions To Analyse LineString Properties

StartPoint(LineString l):Point
The start point of this LineString.
mysql> SELECT AsText(StartPoint(GeomFromText('LineString(1 1,2 2,3 3)')));
+-------------------------------------------------------------+
| AsText(StartPoint(GeomFromText('LineString(1 1,2 2,3 3)'))) |
+-------------------------------------------------------------+
| POINT(1 1)                                                  |
+-------------------------------------------------------------+
EndPoint(LineString l):Point
The end point of this LineString.
mysql> SELECT AsText(EndPoint(GeomFromText('LineString(1 1,2 2,3 3)')));
+------------------------------------------------------------+
| AsText(EndPoint(GeomFromText('LineString(1 1,2 2,3 3)')))  |
+------------------------------------------------------------+
| POINT(3 3)                                                 |
+------------------------------------------------------------+
PointN(LineString l,integer n):Point
Returns the specified point N in this Linestring.
mysql> SELECT AsText(PointN(GeomFromText('LineString(1 1,2 2,3 3)'),2));
+-----------------------------------------------------------+
| AsText(PointN(GeomFromText('LineString(1 1,2 2,3 3)'),2)) |
+-----------------------------------------------------------+
| POINT(2 2)                                                |
+-----------------------------------------------------------+
GLength(LineString l):Double
The length of this LineString in its associated spatial reference.
mysql> SELECT GLength(GeomFromText('LineString(1 1,2 2,3 3)'));
+--------------------------------------------------+
| GLength(GeomFromText('LineString(1 1,2 2,3 3)')) |
+--------------------------------------------------+
|                                  2.8284271247462 |
+--------------------------------------------------+
NumPoints(LineString l):Integer
The number of points in this LineString.
mysql> SELECT NumPoints(GeomFromText('LineString(1 1,2 2,3 3)'));
+----------------------------------------------------+
| NumPoints(GeomFromText('LineString(1 1,2 2,3 3)')) |
+----------------------------------------------------+
|                                                  3 |
+----------------------------------------------------+

Note: MySQL does not yet implement the following functions:

IsRing(LineString l):Integer
Returns 1 (TRUE) if this LineString is closed (StartPoint ( ) = EndPoint ( )) and this LineString is simple (does not pass through the same point more than once).
IsClosed(LineString l):Integer
Returns 1 (TRUE) if this LineString is closed (StartPoint() == EndPoint()).
mysql> SELECT IsClosed(GeomFromText('LineString(1 1,2 2,3 3)'));
+---------------------------------------------------+
| IsClosed(GeomFromText('LineString(1 1,2 2,3 3)')) |
+---------------------------------------------------+
|                                                 0 |
+---------------------------------------------------+

9.5.2.4 Functions To Analyse MultiLineString Properties

GLength(MultiLineString m):Double
The Length of this MultiLineString which is equal to the sum of the lengths of the elements.
mysql> SELECT GLength(GeomFromText('MultiLineString((1 1,2 2,3 3),(4 4,5 5))'));
+-------------------------------------------------------------------+
| GLength(GeomFromText('MultiLineString((1 1,2 2,3 3),(4 4,5 5))')) |
+-------------------------------------------------------------------+
|                                                   4.2426406871193 |
+-------------------------------------------------------------------+
IsClosed(MultiLineString m):Integer
Returns 1 (TRUE) if this MultiLineString is closed (StartPoint() = EndPoint() for each LineString in this MultiLineString).
mysql> SELECT IsClosed(GeomFromText('MultiLineString((1 1,2 2,3 3),(4 4,5 5))'));
+--------------------------------------------------------------------+
| IsClosed(GeomFromText('MultiLineString((1 1,2 2,3 3),(4 4,5 5))')) |
+--------------------------------------------------------------------+
|                                                                  0 |
+--------------------------------------------------------------------+

9.5.2.5 Functions To Analyse Polygon Properties

Area(Polygon p):Double
The area of this Polygon, as measured in the spatial reference system of this Polygon.
mysql> SELECT Area(GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))'));
+----------------------------------------------------------------------------+
| Area(GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))')) |
+----------------------------------------------------------------------------+
|                                                                          8 |
+----------------------------------------------------------------------------+
NumInteriorRings(Polygon p):Integer
Returns the number of interior rings in this Polygon.
mysql> SELECT NumInteriorRings(GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))'));
+----------------------------------------------------------------------------------------+
| NumInteriorRings(GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))')) |
+----------------------------------------------------------------------------------------+
|                                                                                      1 |
+----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
ExteriorRing(Polygon p):LineString
Returns the exterior ring of this Polygon as a LineString.
mysql> SELECT AsText(ExteriorRing(GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))')));
+--------------------------------------------------------------------------------------------+
| AsText(ExteriorRing(GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))'))) |
+--------------------------------------------------------------------------------------------+
| LINESTRING(0 0,0 3,3 3,3 0,0 0)                                                            |
+--------------------------------------------------------------------------------------------+
InteriorRingN(Polygon p, Integer N):LineString
Returns the N-th interior ring for this Polygon as a LineString.
mysql> SELECT AsText(InteriorRingN(GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))'),1));
+-----------------------------------------------------------------------------------------------+
| AsText(InteriorRingN(GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))'),1)) |
+-----------------------------------------------------------------------------------------------+
| LINESTRING(1 1,1 2,2 2,2 1,1 1)                                                               |
+-----------------------------------------------------------------------------------------------+

Note: MySQL does not yet implement the following functions:

Centroid(Polygon p):Point
The mathematical centroid for this Polygon as a Point. The result is not guaranteed to be on this Polygon.
PointOnSurface(p:Polygon):Point
A point guaranteed to be on this Polygon.

9.5.2.6 Functions To Analyse MultiPolygon Properties

Area(MultiPolygon m):Double
The area of this MultiPolygon, as measured in the spatial reference system of this MultiPolygon.
mysql> SELECT Area(GeomFromText('MultiPolygon(((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1)))'));
+-----------------------------------------------------------------------------------+
| Area(GeomFromText('MultiPolygon(((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1)))')) |
+-----------------------------------------------------------------------------------+
|                                                                                 8 |
+-----------------------------------------------------------------------------------+

Note: MySQL does not yet implement the following functions:

Centroid(MultyPolygon p):Point
The mathematical centroid for this MultiPolygon as a Point. The result is not guaranteed to be on this MultiPolygon.
PointOnSurface(MultiPolygon m):Point
A Point guaranteed to be on this MultiPolygon.

9.5.2.7 Functions To Analyse GeometryCollection Properties

NumGeometries(GeometryCollection g):Integer
Returns the number of geometries in this GeometryCollection.
mysql> SELECT NumGeometries(GeomFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))'));
+------------------------------------------------------------------------------------+
| NumGeometries(GeomFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))')) |
+------------------------------------------------------------------------------------+
|                                                                                  2 |
+------------------------------------------------------------------------------------+
GeometryN(GeometryCollection g,integer N):Geometry
Returns the N-th geometry in this GeometryCollection.
mysql> SELECT AsText(GeometryN(GeomFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))'),1));
+------------------------------------------------------------------------------------------+
| AsText(GeometryN(GeomFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))'),1)) |
+------------------------------------------------------------------------------------------+
| POINT(1 1)                                                                               |
+------------------------------------------------------------------------------------------+

Note: Functions for specific geometry type return NULL if the passed geometry is of wrong geometry type. For example Area() returns NULL if object type is neither Polygon nor MultiPolygon.

9.5.3 Functions That Create New Geometries From Existing Ones

9.5.3.1 Geometry Properties That Produce New Geometries

In the section (see section 9.5.2 Functions To Analyse Geometry Properties), we've already discussed some functions that can construct new geometries from the exising ones:

9.5.3.2 Spatial Operators

OpenGIS proposes a number of other functions that can produce geometries. They are designed to implement Spatial Operators.

Note: These functions are not yet implemented. They should appear in the future releases.

Intersection(Geometry g1,g2):Geometry
A geometry that represents the point set intersection of g1 with g2.
Union(Geometry g1,g2):Geometry
A geometry that represents the point set union of g1 with g2.
Difference(Geometry g1,g2):Geometry
A geometry that represents the point set difference of g1 with g2.
SymDifference(Geometry g1,g2):Geometry
A geometry that represents the point set symmetric difference of g1 with g2.
Buffer(Geometry g, double d):Geometry
A geometry that represents all points whose distance from g is less than or equal to distance of d.
ConvexHull(Geometry g):Geometry
A geometry that represents the convex hull of g.

9.5.4 Functions For Testing Spatial Relations Between Geometric Objects

The functions described in this sections take two geometries as input parameters and return a qualitive or quantitive relation between them.

9.5.5 Relations On Geometry Minimal Bounding Rectangles (MBR)

The current release provides some functions that can test relations between mininal bounding rectangles of two geometries. They include:

MBRContains(geom1,geom2)
Returns 1 if the Minimum Bounding Rectangle of geom1 contains the Minimum Bounding Rectangle of geom2. Otherwise, 0 is returned.
mysql> SELECT MBRContains(GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))'),GeomFromText('Point(1 1)'));
+----------------------------------------------------------------------------------------+
| MBRContains(GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))'),GeomFromText('Point(1 1)')) |
+----------------------------------------------------------------------------------------+
|                                                                                      1 |
+----------------------------------------------------------------------------------------+
MBRWithin(geom1,geom2)
Returns 1 if the Minimum Bounding Rectangle of geom1 is within the Minimum Bounding Rectangle of geom2. Otherwise, 0 is returned.
mysql> SELECT MBRWithin(GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))'),GeomFromText('Polygon((0 0,0 5,5 5,5 0,0 0))'));
+----------------------------------------------------------------------------------------------------------+
| MBRWithin(GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))'),GeomFromText('Polygon((0 0,0 5,5 5,5 0,0 0))')) |
+----------------------------------------------------------------------------------------------------------+
|                                                                                                        1 |
+----------------------------------------------------------------------------------------------------------+
MBRDisjoint(geom1,geom2)
Returns 1 if the Minimum Bounding Rectangles of the two geometries do not intersect. Otherwise, 0 is returned.
MBREqual(geom1,geom2)
Returns 1 if the Minimum Bounding Rectangles of the two geometries are the same. Otherwise, 0 is returned.
MBRIntersects(geom1,geom2)
Returns 1 if the Minimum Bounding Rectangles of the two geometries intersect. Otherwise, 0 is returned.
MBROverlaps(geom1,geom2)
Returns 1 if the Minimum Bounding Rectangles of the two geometries overlaps. Otherwise, 0 is returned.
MBRTouches(geom1,geom2)
Returns 1 if the Minimum Bounding Rectangles of the two geometries overlaps. Otherwise, 0 is returned.

9.5.6 Functions That Test Spatial Relationships Between Geometries

Note: The functions given in the list below are not yet implemented. These functions will provide full (not MBR-based only) support for spatial analysis.

Contains(geom1,geom2)
Returns 1 if geom1 completely contains geom2, otherwise 0 is returned.
Crosses(geom1,geom2)
Returns 1 if geom1 spatially crosses geom2. If geom1 is a polygon or a multipolygon, NULL is returned. If geom2 is a point or a multipoint, NULL is returned. Otherwise 0 is returned. The term spatially crosses denotes a spatial relation when two given geometries intersect, and their intersection results in a geometry that has a dimension that is one less than the maximum dimension of the two given geometries, and the intersection is not equal to any of the two given geometries.
Disjoint(geom1,geom2)
Returns 1 if geom1 is spatially disjoint from geom2, i.e. if given geometries do not intersect. Otherwise, 0 is returned.
Equal(geom1,geom2)
Returns 1 if geom1 is spatially equal to geom2, otherwise 0 is returned.
Intersects(geom1,geom2)
Returns 1 if geom1 spatially intersects geom2, otherwise 0 is returned.
Overlaps(geom1,geom2)
Returns 1 if geom1 spatially overlaps geom2, otherwise, 0 is returned. Term spatially overlaps is used if two geometries intersect and their intersection results in a geometry of the same dimension but not equal to either of the given geometries.
Touches(geom1,geom2)
Returns 1 if geom1 spatially touches geom2, otherwise, 0 is returned. Two geometries spatially touch if the interior of both geometries do not intersect, but the boundary of one of the geometries intersects either the boundary or the interioir of the geometries.
Within(geom1,geom2)
Returns 1 if geom1 is spatially within geom2, otherwise, 0 is returned.
Distance(geom1:Geometry,geom2:Geometry):Double
The shortest distance between any two points in the two geometries.

9.6 Optimising Spatial Analysis

It is known that search operations in usual databases can be optimised using indexes. This is still true for spatial databases. With help of great variery of multi-dimensional indexing methods which have already been designed in the world, it's possible to optimise spatial searches, the most typical of which are:

MySQL utilises R-Trees with quadratic splitting to index spatial columns. A spatial index is built using the MBR of a geometry. For most geometries, the MBR is a minimum rectangle that surrounds the geometries. For a horizontal or a vertical linestring as well as for a point, the MBR is a degenerated rectangle, into the linestring and the point respectively.

9.6.1 Creating Spatial Indexes

MySQL can create spatial indexes in the same way it can create regular indexes. The normal syntax for creating indexes is extended with the SPATIAL keyword:

With CREATE TABLE:
CREATE TABLE g (g GEOMETRY NOT NULL, SPATIAL INDEX(g));
With CREATE INDEX:
CREATE SPATIAL INDEX sp_index ON g (g);
With ALTER TABLE:
ALTER TABLE g (ADD SPATIAL KEY(g));

Let's say we have a database with more than 32000 geometries. Geometries are stored in the field g of type GEOMETRY. The table also has a field fid, storing object IDs, with the AUTO_INCREMENT attribute.

mysql> SHOW FIELDS FROM g;
+-------+----------+-----------+------+-----+---------+----------------+
| Field | Type     | Collation | Null | Key | Default | Extra          |
+-------+----------+-----------+------+-----+---------+----------------+
| fid   | int(11)  | binary    |      | PRI | NULL    | auto_increment |
| g     | geometry | binary    |      |     |         |                |
+-------+----------+-----------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql> SELECT COUNT(*) FROM g;
+----------+
| count(*) |
+----------+
|    32376 |
+----------+
1 row in set (0.00 sec)

Let's add a spatial index:

mysql> ALTER TABLE g ADD SPATIAL KEY(g);
Query OK, 32376 rows affected (4.05 sec)
Records: 32376  Duplicates: 0  Warnings: 0

9.6.2 Using a Spatial Index

The optimiser investigates if available spatial indexes can be involved in the search whenever a query with a function like MBRContains() or MBRWithin() in the WHERE clause is executed.

For example, let's say we want to find all objects that are in the given rectangle:

mysql> SELECT fid,AsText(g) FROM g WHERE
mysql> MBRContains(GeomFromText('Polygon((30000 15000,31000 15000,31000 16000,30000 16000,30000 15000))'),g);
+-----+-----------------------------------------------------------------------------+
| fid | AsText(g)                                                                   |
+-----+-----------------------------------------------------------------------------+
|  21 | LINESTRING(30350.4 15828.8,30350.6 15845,30333.8 15845,30333.8 15828.8)     |
|  22 | LINESTRING(30350.6 15871.4,30350.6 15887.8,30334 15887.8,30334 15871.4)     |
|  23 | LINESTRING(30350.6 15914.2,30350.6 15930.4,30334 15930.4,30334 15914.2)     |
|  24 | LINESTRING(30290.2 15823,30290.2 15839.4,30273.4 15839.4,30273.4 15823)     |
|  25 | LINESTRING(30291.4 15866.2,30291.6 15882.4,30274.8 15882.4,30274.8 15866.2) |
|  26 | LINESTRING(30291.6 15918.2,30291.6 15934.4,30275 15934.4,30275 15918.2)     |
| 249 | LINESTRING(30337.8 15938.6,30337.8 15946.8,30320.4 15946.8,30320.4 15938.4) |
|   1 | LINESTRING(30250.4 15129.2,30248.8 15138.4,30238.2 15136.4,30240 15127.2)   |
|   2 | LINESTRING(30220.2 15122.8,30217.2 15137.8,30207.6 15136,30210.4 15121)     |
|   3 | LINESTRING(30179 15114.4,30176.6 15129.4,30167 15128,30169 15113)           |
|   4 | LINESTRING(30155.2 15121.4,30140.4 15118.6,30142 15109,30157 15111.6)       |
|   5 | LINESTRING(30192.4 15085,30177.6 15082.2,30179.2 15072.4,30194.2 15075.2)   |
|   6 | LINESTRING(30244 15087,30229 15086.2,30229.4 15076.4,30244.6 15077)         |
|   7 | LINESTRING(30200.6 15059.4,30185.6 15058.6,30186 15048.8,30201.2 15049.4)   |
|  10 | LINESTRING(30179.6 15017.8,30181 15002.8,30190.8 15003.6,30189.6 15019)     |
|  11 | LINESTRING(30154.2 15000.4,30168.6 15004.8,30166 15014.2,30151.2 15009.8)   |
|  13 | LINESTRING(30105 15065.8,30108.4 15050.8,30118 15053,30114.6 15067.8)       |
| 154 | LINESTRING(30276.2 15143.8,30261.4 15141,30263 15131.4,30278 15134)         |
| 155 | LINESTRING(30269.8 15084,30269.4 15093.4,30258.6 15093,30259 15083.4)       |
| 157 | LINESTRING(30128.2 15011,30113.2 15010.2,30113.6 15000.4,30128.8 15001)     |
+-----+-----------------------------------------------------------------------------+
20 rows in set (0.00 sec)

Now let's check the way this query is executed, using EXPLAIN:

mysql> EXPLAIN SELECT fid,AsText(g) FROM g WHERE
mysql> MBRContains(GeomFromText('Polygon((30000 15000,31000 15000,31000 16000,30000 16000,30000 15000))'),g);
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra       |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
|  1 | SIMPLE      | g     | range | g             | g    |      32 | NULL |   50 | Using where |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

Now let's check what would happen if we didn't have a spatial index:

mysql> EXPLAIN SELECT fid,AsText(g) FROM g IGNORE INDEX (g) WHERE
mysql> MBRContains(GeomFromText('Polygon((30000 15000,31000 15000,31000 16000,30000 16000,30000 15000))'),g);
+----+-------------+-------+------+---------------+------+---------+------+-------+-------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows  | Extra       |
+----+-------------+-------+------+---------------+------+---------+------+-------+-------------+
|  1 | SIMPLE      | g     | ALL  | NULL          | NULL |    NULL | NULL | 32376 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+-------+-------------+
1 row in set (0.00 sec)

Lets execute the above query, ignoring the spatial key we have:

mysql> SELECT fid,AsText(g) FROM g IGNORE INDEX (g) WHERE
mysql> MBRContains(GeomFromText('Polygon((30000 15000,31000 15000,31000 16000,30000 16000,30000 15000))'),g);
+-----+-----------------------------------------------------------------------------+
| fid | AsText(g)                                                                   |
+-----+-----------------------------------------------------------------------------+
|   1 | LINESTRING(30250.4 15129.2,30248.8 15138.4,30238.2 15136.4,30240 15127.2)   |
|   2 | LINESTRING(30220.2 15122.8,30217.2 15137.8,30207.6 15136,30210.4 15121)     |
|   3 | LINESTRING(30179 15114.4,30176.6 15129.4,30167 15128,30169 15113)           |
|   4 | LINESTRING(30155.2 15121.4,30140.4 15118.6,30142 15109,30157 15111.6)       |
|   5 | LINESTRING(30192.4 15085,30177.6 15082.2,30179.2 15072.4,30194.2 15075.2)   |
|   6 | LINESTRING(30244 15087,30229 15086.2,30229.4 15076.4,30244.6 15077)         |
|   7 | LINESTRING(30200.6 15059.4,30185.6 15058.6,30186 15048.8,30201.2 15049.4)   |
|  10 | LINESTRING(30179.6 15017.8,30181 15002.8,30190.8 15003.6,30189.6 15019)     |
|  11 | LINESTRING(30154.2 15000.4,30168.6 15004.8,30166 15014.2,30151.2 15009.8)   |
|  13 | LINESTRING(30105 15065.8,30108.4 15050.8,30118 15053,30114.6 15067.8)       |
|  21 | LINESTRING(30350.4 15828.8,30350.6 15845,30333.8 15845,30333.8 15828.8)     |
|  22 | LINESTRING(30350.6 15871.4,30350.6 15887.8,30334 15887.8,30334 15871.4)     |
|  23 | LINESTRING(30350.6 15914.2,30350.6 15930.4,30334 15930.4,30334 15914.2)     |
|  24 | LINESTRING(30290.2 15823,30290.2 15839.4,30273.4 15839.4,30273.4 15823)     |
|  25 | LINESTRING(30291.4 15866.2,30291.6 15882.4,30274.8 15882.4,30274.8 15866.2) |
|  26 | LINESTRING(30291.6 15918.2,30291.6 15934.4,30275 15934.4,30275 15918.2)     |
| 154 | LINESTRING(30276.2 15143.8,30261.4 15141,30263 15131.4,30278 15134)         |
| 155 | LINESTRING(30269.8 15084,30269.4 15093.4,30258.6 15093,30259 15083.4)       |
| 157 | LINESTRING(30128.2 15011,30113.2 15010.2,30113.6 15000.4,30128.8 15001)     |
| 249 | LINESTRING(30337.8 15938.6,30337.8 15946.8,30320.4 15946.8,30320.4 15938.4) |
+-----+-----------------------------------------------------------------------------+
20 rows in set (0.46 sec)

The execution time for this query rises from 0.00 seconds to 0.46 seconds, when the index is not used.

In the future releases, spatial indexes will also be used for optimising other functions. See section 9.5.4 Functions For Testing Spatial Relations Between Geometric Objects.

9.7 MySQL Conformance And Compatibility

9.7.1 GIS Features That Are Not Yet Implemented

Additional Metadata Views
OpenGIS specifications propose several additional metadata views. For example, a system view named GEOMETRY_COLUMNS contains a description of geometry columns, one row for each geometry column in the database.
Functions to add/drop spatial columns
OpenGIS assumes that columns can be added/dropped using AddGeometryColumn() and DropGeometryColumn() functions correspondently. In MySQL this is to be done using the regular ALTER TABLE command instead.
Spatial Reference Systems and their IDs (SRIDs) related things:
Function Length() on LineString and MultiLineString currently should be called as GLength().
The problem is that it conflicts with a usual function Length() and sometimes it's not possible to distinguish if the function was called in the textual or spatial context. We need either to solve this somehow, or decide on another function name.


Go to the first, previous, next, last section, table of contents.