Skip to content

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

Merged
taylorotwell merged 1 commit into
laravel:5.6from
jochemfuchs:feature/add-support-for-spatial-reference-systems
May 28, 2018
Merged

[5.6] Add support for defining and enforcing a Spatial reference system for a Point column#24320
taylorotwell merged 1 commit into
laravel:5.6from
jochemfuchs:feature/add-support-for-spatial-reference-systems

Conversation

@jochemfuchs

@jochemfuchs jochemfuchs commented May 25, 2018

Copy link
Copy Markdown

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
Copy Markdown
Member

Merged.

@jochemfuchs

Copy link
Copy Markdown
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