Serverless, ReactPHP, and Expanding Frontiers, May 2019

(singke) #1
http://www.phparch.com \ May 2019 \ 17

MySQL 8.0 Geographic Information System or How Did I Get to This Point?

It is easy to check if our data is as we entered it by using ST_
Longitude() and ST_Latitude() to convert it from the internal
binary format to something more readable for humans as
shown in Listing 4.


Listing 4


  1. mysql> SELECT name,

  2. ST_Latitude(loc) as Lat,

  3. ST_Longitude(loc) AS Lon

  4. FROM city;



  5. +-------------+-----------+------------+

  6. | name | Lat | Lon |

  7. +-------------+-----------+------------+

  8. | Justin | 33.09993 | -97.340499 |

  9. | Trophy Club | 33.009335 | -97.22672 |

  10. +-------------+-----------+------------+



  11. 2 rows in set (0.00 sec)
    And now we can use ST_Distance_Sphere() to get the
    distance in meters between the two cities.


SELECT ST_Distance_Sphere(
(SELECT loc FROM city WHERE name='Justin'),
(SELECT loc FROM city WHERE name='Trophy Club')
) as Distance_meters;


And, thus, we find the two cities are 14626.
meters apart. Remember, the proper way to convert meters to
miles is to convert it first to furlongs, cubits, and then smoots!


No, that last sentence was a joke, and I am sure the readers
of this fine publication already have their preferred meters to
mile conversion formula or can find one quickly.


However, this query illustrates the power of having your
database do the calculations for you.


Conclusion
This article has barely scratched the surface of what can be
done with GIS such as drawing a polygon around a location,
say a city limit or postal code area, and doing something
really useful such as finding the pizza restaurants inside that
polygon. There is a lot of fascinating stuff in the GIS world
to read up on, or maybe your job is looking for a way to
corner the market on their new “Piggy Back Ride to Pizza as
a Service” business strategy.

More to Read



Dave Stokes started using PHP when it
was known as Personal Home Page and
started working for MySQL AN as a PHP
Developer. He is now a MySQL
Commmunity Manager for Oracle Corpo-
ration. He lives in Texas with the required
hound dog and pickup truck. @stoker

Related Reading


Free download pdf