Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Spatial Support in MySQL
Norvald H. Ryeng
Software Development Senior Manager
August 30, 2019
2Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Program Agenda
A brief history of GIS in MySQL
Data types
Spatial reference systems
Storage and indexing
Functions on geometries
1
2
3
4
5
6
7
3Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
A Brief History of GIS in MySQL
MySQL ≤5.5: EOL — please upgrade
MySQL 5.6: Homegrown algorithms — please upgrade
MySQL 5.7: A "reboot" of GIS in MySQL
– Aim for standard compliance
● OGC, SQL/MM, etc.
– Use Boost Geometry instead of homegrown algorithms
● Contribute back to Boost
– Cartesian only
MySQL 8.0: Geography (ellipsoids)
– Spatial reference systems
4Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Spatial Support is Built In
● No plugin, it works out of the box
● First class citizen
● Fully integrated with other functionality
– Data dictionary tables
– INFORMATION_SCHEMA views
– Libraries
● GeoJSON parsed with general JSON parser
– Etc.
5Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Data Types
● Geometry
– Point
– Linestring
– Polygon
– GeometryCollection
● MultiPoint
● MultiLinestring
● MultiPolygon
● Same types for Cartesian and geographic data
– SRID decides interpretation
● Only 2d for now
6Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Spatial Reference Systems
SRID 0 Projected SRS Geographic SRS
Cartesian SRS
5.7 8.0
7Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Spatial Reference Systems
● 5151 predefined 2d SRSs from the EPSG Dataset 9.3 (MySQL 8.0.17)
– 4668 projected
– 483 geographic
● CREATE/DROP SPATIAL REFERENCE SYSTEM statements to create your
own
– Stored in data dictionary
– Viewable through INFORMATION_SCHEMA.ST_SPATIAL_REFERENCE_SYSTEMS
● Axis order is defined by the SRS definition
– EPSG SRSs are always lat-long
8Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Geography
● Ellipsoidal SRSs
– Full freedom: Arbitrary semi-major and semi-minor axes, any unit, any
axis direction and axis order
– ST_Transform between different ellipsoids
● All geometries are supported
– Line segments follow geodesics (shortest path)
9Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Storage and Indexing
● Each geometry type can be a column type
● A column can be restricted to a single SRID
● Currently stored as SRID + WKB-ish (X-Y or long-lat)
● R-tree indexes
– Cartesian or geographic
– Indexed columns must be SRID restricted and NOT NULL
10Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
CREATE TABLE t (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
pt POINT SRID 4326 NOT NULL
);
CREATE INDEX pt_idx ON t(pt);
INSERT INTO t VALUES (pt)
(ST_GeomFromText('POINT(44.4355 26.1025)', 4326));
INSERT INTO t VALUES (pt)
(ST_GeomFromText('POINT(26.1025 44.4355)', 4326,
'axis-order=long-lat'));
11Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
SELECT id, ST_AsText(pt) FROM t;
SELECT id, ST_AsText(pt, 'axis-order=lat-long') FROM t;
SELECT id, ST_AsText(pt, 'axis-order=long-lat') FROM t;
12Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Functions on Geometries
● Import
– ST_GeomCollFromTxt/ST_GeomCollFromText, ST_GeomCollFromWKB,
ST_GeomFromGeoJSON, ST_GeomFromText, ST_GeomFromWKB,
ST_LineFromText, ST_LineFromWKB, ST_MLineFromText,
ST_MLineFromWKB, ST_MPointFromText, ST_MPointFromWKB,
ST_MPolyFromText, ST_MPolyFromWKB, ST_PointFromGeohash,
ST_PolyFromText, ST_PolyFromWKB
● Export
– ST_AsBinary, ST_AsGeoJSON, ST_AsText, ST_Geohash
13Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Functions on Geometries
● Comparison
– ST_Contains, ST_Crosses, ST_Disjoint, ST_Equals, ST_Intersects,
ST_Overlaps, ST_Touches, ST_Within
– MBRContains, MBRCoveredBy, MBRCovers, MBRDisjoint, MBREquals,
MBRIntersects, MBROverlaps, MBRTouches, MBRWithin
● Produce new geometries
– ST_Buffer, ST_Centroid, ST_ConvexHull, ST_Envelope,
ST_MakeEnvelope, ST_Simplify, ST_Difference, ST_Intersection,
ST_SymDifference, ST_Union
14Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Functions on Geometries
● Measures
– ST_Area, ST_Distance, ST_Distance_Sphere, ST_Length
● Extract/modify properties
– ST_Dimension, ST_EndPoint, ST_ExteriorRing, ST_GeometryN,
ST_GeometryType, ST_InteriorRingN, ST_IsClosed, ST_IsEmpty,
ST_IsSimple, ST_IsValid, ST_PointN, ST_SRID, ST_StartPoint, ST_X, ST_Y,
ST_Latitude, ST_Longitude
● Helper functions
– ST_LatFromGeohash, ST_LongFromGeohash, ST_Validate, ST_SwapXY
15Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Functions on Geometries
● Same functions for Cartesian and geographic data
● General rule/goal: All functions support all geometries and
SRIDs
– Some exceptions where it doesn't make sense or we're waiting for
Boost Geometry
● Many functions already support geography
– Geography support is added piece by piece, function by function
● Added to Boost Geometry first, then to MySQL
● Your favorite function may be next
16Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Contributions Wanted
● We'd love to see MySQL support in all GIS applications
● A lot of the software already has some level of MySQL support
– Often unmaintained or lacking in functionality
– Not utilizing MySQL 8.0 improvements
● Please contribute patches to your favorite applications!
– Ask us for help if needed
– Tell us what is missing on the MySQL side
– Let us know what you've done, and we'll help you spread the good news!
17Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Feature descriptions and design details
directly from the source.
http://mysqlserverteam.com/
18Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
19Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
Safe Harbor Statement
The preceding is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
Spatial Support in MySQL

Spatial Support in MySQL

  • 1.
    Copyright © 2019Oracle and/or its affiliates. All rights reserved. Spatial Support in MySQL Norvald H. Ryeng Software Development Senior Manager August 30, 2019
  • 2.
    2Copyright © 2019Oracle and/or its affiliates. All rights reserved. Program Agenda A brief history of GIS in MySQL Data types Spatial reference systems Storage and indexing Functions on geometries 1 2 3 4 5 6 7
  • 3.
    3Copyright © 2019Oracle and/or its affiliates. All rights reserved. A Brief History of GIS in MySQL MySQL ≤5.5: EOL — please upgrade MySQL 5.6: Homegrown algorithms — please upgrade MySQL 5.7: A "reboot" of GIS in MySQL – Aim for standard compliance ● OGC, SQL/MM, etc. – Use Boost Geometry instead of homegrown algorithms ● Contribute back to Boost – Cartesian only MySQL 8.0: Geography (ellipsoids) – Spatial reference systems
  • 4.
    4Copyright © 2019Oracle and/or its affiliates. All rights reserved. Spatial Support is Built In ● No plugin, it works out of the box ● First class citizen ● Fully integrated with other functionality – Data dictionary tables – INFORMATION_SCHEMA views – Libraries ● GeoJSON parsed with general JSON parser – Etc.
  • 5.
    5Copyright © 2019Oracle and/or its affiliates. All rights reserved. Data Types ● Geometry – Point – Linestring – Polygon – GeometryCollection ● MultiPoint ● MultiLinestring ● MultiPolygon ● Same types for Cartesian and geographic data – SRID decides interpretation ● Only 2d for now
  • 6.
    6Copyright © 2019Oracle and/or its affiliates. All rights reserved. Spatial Reference Systems SRID 0 Projected SRS Geographic SRS Cartesian SRS 5.7 8.0
  • 7.
    7Copyright © 2019Oracle and/or its affiliates. All rights reserved. Spatial Reference Systems ● 5151 predefined 2d SRSs from the EPSG Dataset 9.3 (MySQL 8.0.17) – 4668 projected – 483 geographic ● CREATE/DROP SPATIAL REFERENCE SYSTEM statements to create your own – Stored in data dictionary – Viewable through INFORMATION_SCHEMA.ST_SPATIAL_REFERENCE_SYSTEMS ● Axis order is defined by the SRS definition – EPSG SRSs are always lat-long
  • 8.
    8Copyright © 2019Oracle and/or its affiliates. All rights reserved. Geography ● Ellipsoidal SRSs – Full freedom: Arbitrary semi-major and semi-minor axes, any unit, any axis direction and axis order – ST_Transform between different ellipsoids ● All geometries are supported – Line segments follow geodesics (shortest path)
  • 9.
    9Copyright © 2019Oracle and/or its affiliates. All rights reserved. Storage and Indexing ● Each geometry type can be a column type ● A column can be restricted to a single SRID ● Currently stored as SRID + WKB-ish (X-Y or long-lat) ● R-tree indexes – Cartesian or geographic – Indexed columns must be SRID restricted and NOT NULL
  • 10.
    10Copyright © 2019Oracle and/or its affiliates. All rights reserved. CREATE TABLE t ( id INTEGER AUTO_INCREMENT PRIMARY KEY, pt POINT SRID 4326 NOT NULL ); CREATE INDEX pt_idx ON t(pt); INSERT INTO t VALUES (pt) (ST_GeomFromText('POINT(44.4355 26.1025)', 4326)); INSERT INTO t VALUES (pt) (ST_GeomFromText('POINT(26.1025 44.4355)', 4326, 'axis-order=long-lat'));
  • 11.
    11Copyright © 2019Oracle and/or its affiliates. All rights reserved. SELECT id, ST_AsText(pt) FROM t; SELECT id, ST_AsText(pt, 'axis-order=lat-long') FROM t; SELECT id, ST_AsText(pt, 'axis-order=long-lat') FROM t;
  • 12.
    12Copyright © 2019Oracle and/or its affiliates. All rights reserved. Functions on Geometries ● Import – ST_GeomCollFromTxt/ST_GeomCollFromText, ST_GeomCollFromWKB, ST_GeomFromGeoJSON, ST_GeomFromText, ST_GeomFromWKB, ST_LineFromText, ST_LineFromWKB, ST_MLineFromText, ST_MLineFromWKB, ST_MPointFromText, ST_MPointFromWKB, ST_MPolyFromText, ST_MPolyFromWKB, ST_PointFromGeohash, ST_PolyFromText, ST_PolyFromWKB ● Export – ST_AsBinary, ST_AsGeoJSON, ST_AsText, ST_Geohash
  • 13.
    13Copyright © 2019Oracle and/or its affiliates. All rights reserved. Functions on Geometries ● Comparison – ST_Contains, ST_Crosses, ST_Disjoint, ST_Equals, ST_Intersects, ST_Overlaps, ST_Touches, ST_Within – MBRContains, MBRCoveredBy, MBRCovers, MBRDisjoint, MBREquals, MBRIntersects, MBROverlaps, MBRTouches, MBRWithin ● Produce new geometries – ST_Buffer, ST_Centroid, ST_ConvexHull, ST_Envelope, ST_MakeEnvelope, ST_Simplify, ST_Difference, ST_Intersection, ST_SymDifference, ST_Union
  • 14.
    14Copyright © 2019Oracle and/or its affiliates. All rights reserved. Functions on Geometries ● Measures – ST_Area, ST_Distance, ST_Distance_Sphere, ST_Length ● Extract/modify properties – ST_Dimension, ST_EndPoint, ST_ExteriorRing, ST_GeometryN, ST_GeometryType, ST_InteriorRingN, ST_IsClosed, ST_IsEmpty, ST_IsSimple, ST_IsValid, ST_PointN, ST_SRID, ST_StartPoint, ST_X, ST_Y, ST_Latitude, ST_Longitude ● Helper functions – ST_LatFromGeohash, ST_LongFromGeohash, ST_Validate, ST_SwapXY
  • 15.
    15Copyright © 2019Oracle and/or its affiliates. All rights reserved. Functions on Geometries ● Same functions for Cartesian and geographic data ● General rule/goal: All functions support all geometries and SRIDs – Some exceptions where it doesn't make sense or we're waiting for Boost Geometry ● Many functions already support geography – Geography support is added piece by piece, function by function ● Added to Boost Geometry first, then to MySQL ● Your favorite function may be next
  • 16.
    16Copyright © 2019Oracle and/or its affiliates. All rights reserved. Contributions Wanted ● We'd love to see MySQL support in all GIS applications ● A lot of the software already has some level of MySQL support – Often unmaintained or lacking in functionality – Not utilizing MySQL 8.0 improvements ● Please contribute patches to your favorite applications! – Ask us for help if needed – Tell us what is missing on the MySQL side – Let us know what you've done, and we'll help you spread the good news!
  • 17.
    17Copyright © 2019Oracle and/or its affiliates. All rights reserved. Feature descriptions and design details directly from the source. http://mysqlserverteam.com/
  • 18.
    18Copyright © 2019Oracle and/or its affiliates. All rights reserved.
  • 19.
    19Copyright © 2019Oracle and/or its affiliates. All rights reserved. Safe Harbor Statement The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.