Chapter 19. Spatial Extensions in MySQL

Table of Contents

19.1. Introduction
19.2. The OpenGIS Geometry Model
19.2.19.2.1. The Geometry Class Hierarchy
19.2.19.2.2. Class Geometry
19.2.19.2.3. Class Point
19.2.19.2.4. Class Curve
19.2.19.2.5. Class LineString
19.2.19.2.6. Class Surface
19.2.19.2.7. Class Polygon
19.2.19.2.8. Class GeometryCollection
19.2.19.2.9. Class MultiPoint
19.2.19.2.10. Class MultiCurve
19.2.19.2.11. Class MultiLineString
19.2.19.2.12. Class MultiSurface
19.2.19.2.13. Class MultiPolygon
19.3. Supported Spatial Data Formats
19.3.19.3.1. Well-Known Text (WKT) Format
19.3.19.3.2. Well-Known Binary (WKB) Format
19.4. Creating a Spatially Enabled MySQL Database
19.4.19.4.1. MySQL Spatial Data Types
19.4.19.4.2. Creating Spatial Values
19.4.19.4.3. Creating Spatial Columns
19.4.19.4.4. Populating Spatial Columns
19.4.19.4.5. Fetching Spatial Data
19.5. Analyzing Spatial Information
19.5.19.5.1. Geometry Format Conversion Functions
19.5.19.5.2. Geometry Functions
19.5.19.5.3. Functions That Create New Geometries from Existing Ones
19.5.19.5.4. Functions for Testing Spatial Relations Between Geometric Objects
19.5.19.5.5. Relations on Geometry Minimal Bounding Rectangles (MBRs)
19.5.19.5.6. Functions That Test Spatial Relationships Between Geometries
19.6. Optimizing Spatial Analysis
19.6.19.6.1. Creating Spatial Indexes
19.6.19.6.2. Using a Spatial Index
19.7. MySQL Conformance and Compatibility
19.7.19.7.1. GIS Features That Are Not Yet Implemented

MySQL 4.1 introduces spatial extensions to allow the generation, storage, and analysis of geographic features. Currently, these features are available for MyISAM tables only.

This chapter covers the following topics:

Introduction

MySQL implements spatial extensions following the specification of the Open GIS Consortium (OGC). This is an international consortium of more than 250 companies, agencies, and universities participating in the development of publicly available conceptual solutions that can be useful with all kinds of applications that manage spatial data. The OGC maintains a Web site at http://www.opengis.org/.

In 1997, the Open GIS Consortium published the OpenGIS (R) Simple Features Specifications For SQL, a document that proposes several conceptual ways for extending an SQL RDBMS to support spatial data. This specification is available from the Open GIS Web site at http://www.opengis.org/docs/99-049.pdf. It contains additional information relevant to this chapter.

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 that has a geometry type. The specifications describe a set of SQL geometry types, as well as functions on those types to create and analyze geometry values.

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

  • An entity. For example, a mountain, a pond, a city.

  • A space. For example, a postcode area, the tropics.

  • A definable location. For example, a crossroad, as a particular place where two streets intersect.

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

Geometry is another word that denotes a geographic feature. Originally the word geometry meant measurement of the earth. Another meaning comes from cartography, referring to the geometric features that cartographers use to map the world.

This chapter uses all of these terms synonymously: geographic feature, geospatial feature, feature, or geometry. The term most commonly used here is geometry.

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