PyMySQL
The popular MySQL (available at http://dev.mysql.com/downloads) database is gradually evolving spatial functions. It has support for OGC geometries and a few spatial functions. It also has a pure Python API available in the PyMySQL library. The limited spatial functions use planar geometry and bounding rectangles as opposed to spherical geometry and shapes. The latest development release of MySQL contains some additional functions that improve this capability.
In the following example, we'll create a database in MySQL called spatial_db
. Then, we'll add a table called PLACES
with a geometry
column. Next, we'll add two cities as point locations. And finally, we'll calculate the distance using MySQL's ST_Distance
function and then convert the result from degrees to miles:
>>> import pymysql >>> conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='', db='mysql') >>> cur = conn.cursor() >>> cur.execute("DROP DATABASE IF EXISTS spatial_db...