django/django — pull request #2574 by visu (2014-04-16 16:39:02+00:00)
Title: geodjango leverages mysql 5.6 spatial functions

MySQL 5.6.1 supports proper spatial checks for some of the functions. ( spatial object checks instead of bounding box checks).

waiting for reviewer.

Unit Test:

I have three shapes with one shape overalapping the other two.
[City of SF shape overlapping South of Market neighborhood and Downtown neighborhood].
I selected a point near South of Market neighborhood, such that bounding box check returns all three shapes, while ST_contains returns two. (SoMA and SF).

MySQL query (5.6.1 where st_ functions are implemented):

mysql> select count(*) from athome_shape where st_contains(geom, point(-122.4158771, 37.7792381));
+----------+
| count(*) |
+----------+
| 2 |
+----------+
1 row in set (0.00 sec)

mysql> select count(*) from athome_shape where mbrcontains(geom, point(-122.4158771, 37.7792381));
+----------+
| count(*) |
+----------+
| 3 |
+----------+
1 row in set (0.00 sec)

mysql>

Django Test: (in older version, it would have returned 3 for both the queries).

point_wkt = 'POINT(-122.4158771 37.7792381)'
In [8]: y = Shape.objects.filter(geom__contains=point_wkt)

In [9]: y.count()
Out[9]: 2

In [10]: y = Shape.objects.filter(geom__bbcontains=point_wkt)

In [11]: y.count()
Out[11]: 3