Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Add support for defining and enforcing a Spatial reference system for a Point column #24320

Conversation

jochemfuchs
Copy link

@jochemfuchs jochemfuchs commented May 25, 2018

As of Mysql 8, there is support for spatial reference systems. Currently there is no way to create a Point column that refers to a specific SRS.

The benefit of having this, is to ensure that when using point datatypes for geocoordinates, they on the correct scale. By default the column will refer to SRID 0, and when doing calculations ( e.g. distance between points ) the resulting deviation is huge.

mysql> SELECT ST_distance_sphere( 
( SELECT location FROM locations_without_srsid LIMIT 1), 
(SELECT location FROM locations_without_srsid LIMIT 1, 1) 
)/1000 as distance_in_meters;
+--------------------+
| distance_in_meters |
+--------------------+
| 10.980785022158566 |
+--------------------+
1 row in set (0,00 sec)

mysql> SELECT ST_distance_sphere( 
( SELECT location FROM locations_with_srsid LIMIT 1), 
(SELECT location FROM locations_with_srsid LIMIT 1, 1) 
)/1000 as distance_in_meters;
+--------------------+
| distance_in_meters |
+--------------------+
|  7.221216762563222 |
+--------------------+
1 row in set (0,00 sec)

You can also set the SRID of a point column on INSERT or UPDATE, but with this in place you can prevent entry of incorrect points.

With Mysql 8, I suspect these SRS systems will be used a lot.

See: https://mysqlserverteam.com/spatial-reference-systems-in-mysql-8-0/
See: https://dev.mysql.com/doc/refman/8.0/en/spatial-reference-systems.html

@jochemfuchs jochemfuchs force-pushed the feature/add-support-for-spatial-reference-systems branch from 5df38c1 to 22df6bd Compare May 25, 2018 15:20
@jochemfuchs jochemfuchs force-pushed the feature/add-support-for-spatial-reference-systems branch from 22df6bd to ddc4e05 Compare May 25, 2018 15:21
@GrahamCampbell GrahamCampbell changed the title Add support for defining and enforcing a Spatial reference system for a Point column. [5.6] Add support for defining and enforcing a Spatial reference system for a Point column May 26, 2018
@taylorotwell taylorotwell merged commit ddc4e05 into laravel:5.6 May 28, 2018
@taylorotwell
Copy link
Member

Merged.

@jochemfuchs
Copy link
Author

Awesome! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants