Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MySQL 8.0 GIS Overview

203 views

Published on

A short overview of spatial support in MySQL 8.0, covering spatial data types, coordinate reference systems, functions and indexes, including examples

Published in: Software
  • Be the first to comment

  • Be the first to like this

MySQL 8.0 GIS Overview

  1. 1. Copyright © 2018 Oracle and/or its afliates. All rights reserved. MySQL 8.0 GIS Overview Norvald H. Ryeng Sofware Engineer March 2018
  2. 2. 3Copyright © 2018 Oracle and/or its afliates. All rights reserved. Safe Harbor Statement The following is intended to outline our general product directon. It is intended for informaton purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functonality, and should not be relied upon in making purchasing decisions. The development, release, and tming of any features or functonality described for Oracle’s products remains at the sole discreton of Oracle.
  3. 3. 4Copyright © 2018 Oracle and/or its afliates. All rights reserved. Agenda Data Types Spatal Reference Systems Functons Indexes Upgrade Issues 1 2 3 4 5 6 7
  4. 4. 5Copyright © 2018 Oracle and/or its afliates. All rights reserved. Data Types ● Geometry – Point – Linestring – Polygon – Geometry collecton ● Multpoint ● Multlinestring ● Multpolygon Non-instantable, but can be used as column type.
  5. 5. 6Copyright © 2018 Oracle and/or its afliates. All rights reserved. Spatal Reference Systems SRID 0 Projected SRS Cartesian SRS 5.7 8.0 Geographic SRS
  6. 6. 7Copyright © 2018 Oracle and/or its afliates. All rights reserved. Spatal Reference Systems ● Each SRS has a unique spatal reference system ID (SRID) – Numeric identfer – No formal standard/catalog of SRIDs – De facto standard: EPSG Dataset ● 4326 = WGS 84 (“GPS coordinates”) ● 3857 = WGS 84 / World Mercator (“Web Mercator”) ● A property of each geometry value ● Mixing geometries in diferent SRIDs in one computaton doesn't make sense and will raise an error (also in 5.7)
  7. 7. 8Copyright © 2018 Oracle and/or its afliates. All rights reserved. Spatal Reference Systems ● 5107 predefned SRSs from the EPSG Dataset 9.2 (MySQL 8.0.4) – 4628 projected – 479 geographic ● Exposed through an INFORMATION_SCHEMA view, ST_SPATIAL_REFERENCE_SYSTEMS ● CREATE/DROP SPATIAL REFERENCE SYSTEM statements to create your own
  8. 8. 9Copyright © 2018 Oracle and/or its afliates. All rights reserved. Example CREATE TABLE cites ( id INTEGER AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20) NOT NULL, loc POINT SRID 4326 NOT NULL ); INSERT INTO cites (name, loc) VALUES ( 'Trondheim', ST_GeomFromText('POINT(63.43048320193547 10.394972698312927)', 4326) ); INSERT INTO cites (name, loc) VALUES ( 'San Francisco', ST_GeomFromText('POINT(37.2726156666666667 -122.44254551944445)', 4326) );
  9. 9. 10Copyright © 2018 Oracle and/or its afliates. All rights reserved. Functons ● 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
  10. 10. 11Copyright © 2018 Oracle and/or its afliates. All rights reserved. Functons ● 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_Bufer, ST_Centroid, ST_ConvexHull, ST_Envelope, ST_MakeEnvelope, ST_Simplify, ST_Diference, ST_Intersecton, ST_SymDiference, ST_Union
  11. 11. 12Copyright © 2018 Oracle and/or its afliates. All rights reserved. Functons
  12. 12. 13Copyright © 2018 Oracle and/or its afliates. All rights reserved. Functons ● Measures – ST_Area, ST_Distance, ST_Distance_Sphere, ST_Length ● Extract propertes – ST_GeometryN, ST_GeometryType, ST_InteriorRingN, ST_IsClosed, ST_IsEmpty, ST_IsSimple, ST_IsValid, ST_PointN, ST_SRID, ST_StartPoint, ST_X, ST_Y ● Helper functons – ST_LatFromGeohash, ST_LongFromGeohash, ST_Validate, ST_SwapXY
  13. 13. 14Copyright © 2018 Oracle and/or its afliates. All rights reserved. Example SELECT ST_Distance( (SELECT loc FROM cites WHERE name='Trondheim'), (SELECT loc FROM cites WHERE name='San Francisco') ) AS exact_distance; exact_distance 8089891.633435546 SELECT ST_Distance_Sphere( (SELECT loc FROM cites WHERE name='Trondheim'), (SELECT loc FROM cites WHERE name='San Francisco') ) AS approx_distance; approx_distance 8068723.414049273
  14. 14. 15Copyright © 2018 Oracle and/or its afliates. All rights reserved. Indexes ● R-tree indexes on spatal data – Cartesian or geographic, depending on SRID ● Geographic R-trees in InnoDB only ● Used automatcally by the optmizer – Triggered by use of spatal relatons (ST_Within, etc.) – Cost based decision making
  15. 15. 16Copyright © 2018 Oracle and/or its afliates. All rights reserved. Example CREATE SPATIAL INDEX loc_idx ON cites (loc); SET @europe=ST_GeomFromText('POLYGON((2.49 83.51,-15.09 68.37,-28.80 66.19,-12.63 35.10,6.71 38.48,23.23 33.94,29.56 43.51,38.00 43.51,60.85 69.98,78.42 83.51,2.49 83.51))', 4326, 'axis- order=long-lat'); SELECT name FROM cites WHERE ST_Within(loc, @europe); exact_distance Trondheim EXPLAIN SELECT name FROM cites WHERE ST_Within(loc, @europe); +----+-------------+--------+------------+-------+---------------+---------+---------+------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+--------+------------+-------+---------------+---------+---------+------+------+----------+-------------+ | 1 | SIMPLE | cities | NULL | range | loc_idx | loc_idx | 34 | NULL | 2 | 100.00 | Using where | +----+-------------+--------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
  16. 16. Copyright © 2018 Oracle and/or its afliates. All rights reserved. Upgrade Issues
  17. 17. 18Copyright © 2018 Oracle and/or its afliates. All rights reserved. Upgrade Issues ● YES, there are upgrade issues! – We're sorry, but we have to … ● All EPSG SRSs are lattude frst, longitude second – WKT and WKB input/output uses SRS axis order by default ● Can be overridden with 'axis-order=long-lat' ● Override opton not available in 5.7 – Earlier MySQL versions don't understand axis order, X=X and Y=Y – Queries and/or scripts must be changed ● Storage format is stll longitude frst, lattude second – Compatble with the limited geography support in 5.7
  18. 18. 19Copyright © 2018 Oracle and/or its afliates. All rights reserved. Upgrade Issues ● SRID 0 is the safe choice if using MySQL pre 8.0 – Set correct SRS afer upgrading ● Indexes must be recreated afer upgrade – Column defniton must be modifed to use SRID restricton frst ● The SRID restricton is not available in 5.7 – Indexes on columns without SRID restricton will never be used ● Ignored by the optmizer ● Allowed to exist in order to preserve dump-restore compatbility ● Warnings will be issued
  19. 19. 20Copyright © 2018 Oracle and/or its afliates. All rights reserved. ✓✓ Prepare Now ● Think through your use of SRIDs – Use SRID 0 if you're unsure ● Use longitude-lattude ordering in 5.7 – But remember that import and export functons follow SRS defned axis order in 8.0 ● Use one SRID in each column – Be ready to add SRID restrictons to columns and rebuild indexes in 8.0
  20. 20. Copyright © 2018 Oracle and/or its afliates. All rights reserved. Feature descriptons and design details directly from the source. https:/ppmysslsserverteamy.comyp
  21. 21. 22Copyright © 2018 Oracle and/or its afliates. All rights reserved.

×