Chapter 136. Creating a Spatially Enabled MySQL Database

Table of Contents

MySQL Spatial Datatypes
Creating Spatial Values
Creating Geometry Values Using WKT Functions
Creating Geometry Values Using WKB Functions
Creating Geometry Values Using MySQL-Specific Functions
Creating Spatial Columns
Populating Spatial Columns
Fetching Spatial Data
Fetching Spatial Data in Internal Format
Fetching Spatial Data in WKT Format
Fetching Spatial Data in WKB Format

This section describes the datatypes you can use for representing spatial data in MySQL, and the functions available for creating and retrieving spatial values.

MySQL Spatial Datatypes

MySQL provides a set of datatypes that correspond to classes in the class hierarchy of the OpenGIS Geometry Model. Some of these types hold single geometry values:

  • GEOMETRY

  • POINT

  • LINESTRING

  • POLYGON

GEOMETRY is the most general of these single-value types; it can store geometry values of any type. The others restrict their values to a particular geometry type.

The other datatypes hold collections of values:

  • MULTIPOINT

  • MULTILINESTRING

  • MULTIPOLYGON

  • GEOMETRYCOLLECTION

GEOMETRYCOLLECTION can store a collection of objects of any type. The other collection types restrict collection members to those having a particular geometry type.