Geodjango with Mysql coordinates/polygons precision
I've created a geodjango database working with MySQL.
My problem is that when I add a new record with a PolygonField and then check
for a point if it is inside this polygon I get a wrong results (more points then I should have). I use [Location.objects.filter(shape__contains='POINT(-0.058188 51.504289)')]
to check for a point inside a polygon shape.
My model is:
class Location(models.Model):
locationId = models.IntegerField(unique=True)
shape = models.PolygonField(null=True, blank=True)
objects = models.GeoManager()
To add my shape into a database I used:
polygon = Polygon(((-0.076406999999999975,51.495287999999995),(-0.076412999999999953,51.495159000000008), …(-0.076406999999999975,51.495287999999995)))
Please see this image http://i.stack.imgur.com/qRSnX.png Even on the map in geodjango admin we can see that the boarders of开发者_运维问答 this polygon are not in the correct pleace.
I was using a simple python script like this to compare my results with geodjango: http://geospatialpython.com/2011/01/point-in-polygon.html
Thank you for your help
Quote Justin Bronn:
"MySQL is a crippled spatial database..."
Instead of contains it actually executes bbcontains, and is well known for unreliable results. https://code.djangoproject.com/ticket/13430
I'd suggest moving to PostgreSQL.
I don't have answer if it's not an option.
Thank you for your help. Finally I've used a two-phase approach:
** - First step** is to check for a list of results using shape__contains
** - Second step** is to loop through those results and check if a point is inside those polygons using polygon.intersects(locationPoint)
精彩评论