MySQL 8.0: GIS — Are you ready?

23
Copyright © 2017 Oracle and/or its affiliates. All rights reserved. MySQL 8.0: GIS — Are you ready? Norvald H. Ryeng Soſtware Engineer Pre-FOSDEM MySQL Day 2017

Transcript of MySQL 8.0: GIS — Are you ready?

Page 1: MySQL 8.0: GIS — Are you ready?

Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

MySQL 8.0: GIS — Are you ready?

Norvald H. RyengSoftware Engineer

Pre-FOSDEM MySQL Day 2017

Page 2: MySQL 8.0: GIS — Are you ready?

4Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

Safe Harbor Statement

The following 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.

Page 3: MySQL 8.0: GIS — Are you ready?

5Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

AgendaGIS basics

What's new in MySQL 8.0?

What can I do now to prepare for what's coming?

1

2

3

4

5

6

7

Page 4: MySQL 8.0: GIS — Are you ready?

6Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

“The early days of GIS were very lonely. No-one knew what it meant.”— Roger Tomlinson, “Father of GIS”

Page 5: MySQL 8.0: GIS — Are you ready?

7Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

GIS basics: Geometries (= geometric objects)● Geometry

– Point

– LineString

– Polygon

– GeometryCollection

● MultiPoint

● MultiLineString

● MultiPolygon

Page 6: MySQL 8.0: GIS — Are you ready?

11Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

GIS basics: Spatial reference systems

SRID 0 Projected SRS Geographic SRS

Cartesian SRS

5.7 8.0

Page 7: MySQL 8.0: GIS — Are you ready?

12Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

GIS basics: Spatial reference systems● Each SRS has a unique spatial reference system ID (SRID)

– Numeric identifier

– 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

● Mixing geometries in different SRIDs in one computation doesn't make sense and will raise an error (also in 5.7)

Page 8: MySQL 8.0: GIS — Are you ready?

13Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

“Geography is just physics slowed down, with a couple of trees stuck in it.”— Terry Pratchett in The Last Continent

Page 9: MySQL 8.0: GIS — Are you ready?

14Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

What's new in MySQL 8.0● Geography

– Earth is round(ish)

– Lines are not straight

– The coordinate system wraps: -180, 180]⟨● Spatial reference systems

– Most are still flat (projections)

– Geographic SRSs will affect the result of most computations

Page 10: MySQL 8.0: GIS — Are you ready?

15Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

5.7● The world is flat

● The world is infinite

● Axes are unitless

● Axes are orthogonal

● Axis order is irrelevant

● Axis direction is irrelevant

8.0● The world can be flat or ellipsoidal

● Geographic coordinate systems wrap around

● Axes have units

● Geographic axes are not orthogonal

● Geographic axis order matters

● Axis direction may be relevant

Page 11: MySQL 8.0: GIS — Are you ready?

Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

What can I do now to prepare for what's coming?

Page 12: MySQL 8.0: GIS — Are you ready?

17Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

Cartesian vs. geographic● Operations on geometries in geographic SRSs will be computed in

geographic SRSs

● How do I know which SRS my geometries are in?

– SELECT ST_SRID(geometry);

– MySQL uses EPSG codes as SRIDs

● http://www.epsg-registry.org/

● Changing SRID in 5.7 is a bit complicated: ST_GeomFromWKB(ST_AsBinary(geometry), srid)

– In 8.0: ST_SRID(geometry, srid)

Page 13: MySQL 8.0: GIS — Are you ready?

18Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

✓✓Prepare now: Use the right SRID● If you know your data is in a projected SRS, use the correct SRID

– No surprises when upgrading to 8.0

– Semantically correct, carries metadata about units, etc.

● If your data is in a geographic SRS and you know what you're doing, use the correct SRS or SRID 0

– SRID 0 will give you no surprises when upgrading to 8.0

– Geographic SRSs will affect query results

● If you're unsure which SRS/SRID to use, use SRID 0

– No surprises when upgrading to 8.0

– Makes no claim about the SRS except that it's flat

Page 14: MySQL 8.0: GIS — Are you ready?

19Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

POINT(50.8267054 4.3980435)

Page 15: MySQL 8.0: GIS — Are you ready?

20Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

Longitude and latitude … or latitude and longitude● The “normal” order is latitude first, longitude second

… except in GIS

● Many GIS applications assume longitude-latitude

● ISO and the Open Geospatial Consortium have agreed

– Always use the order specified for the SRS

– Software packages are still trying to adapt

● All geographic SRSs in the EPSG Dataset define latitude-longitude ordering

● MySQL uses the EPSG Dataset

Page 16: MySQL 8.0: GIS — Are you ready?

21Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

Axis order in MySQL● Stored as X=longitude, Y=latitude on disk

– Expected by ST_Distance_Sphere and GeoJSON functions in 5.7

8.0

● Import/export functions will let you choose geographic axis order

– Default: SRS defined (predefined SRSs: latitude-longitude)

– ST_GeomFromText('POINT(1 2)', 4326, 'axis-order=long-lat')

● Function to swap coordinates: ST_SwapXY(geometry)

Page 17: MySQL 8.0: GIS — Are you ready?

22Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

✓Prepare now: Axis order● If you store angular coordinates, use X=longitude and

Y=latitude

– Not necessary to swap coordinates in 8.0

– Think carefully about the choice of SRID

– Beware of changes in computations in 8.0

● Import/export in SRID 0 is always X first, Y second

Page 18: MySQL 8.0: GIS — Are you ready?

23Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

Axis direction● Defined in the SRS

● Doesn't matter on an abstract Cartesian plane (SRID 0)

● Matters on georeferenced planes (projections)

– But doesn't affect computations

● Matters in geographic SRSs

– But doesn't affect computations

– May affect results if the meridian is not through Greenwich● Coercion to -180, 180]⟨

Page 19: MySQL 8.0: GIS — Are you ready?

24Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

Prepare now: Axis direction● It probably won't affect you

● But do it right still! ✓

Page 20: MySQL 8.0: GIS — Are you ready?

25Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

“GIS is a form of digital mapping technology. Kind of like Google Earth, but better.”— Arnold Schwarzenegger, Governor of California

Page 21: MySQL 8.0: GIS — Are you ready?

26Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

✓✓Prepare now● Think through your use of SRIDs

– Use SRID 0 if you're unsure

● Use longitude-latitude ordering in 5.7

– But remember that import and export functions follow SRS defined axis order in 8.0

● Think through axis directions

● Follow the progress of MySQL 8.0 GIS development at http://www.mysqlserverteam.com/

Page 22: MySQL 8.0: GIS — Are you ready?

27Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

Page 23: MySQL 8.0: GIS — Are you ready?