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 https://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
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)