I'm going through the Geodjango tutorial and trying to implement in my own project - I have loaded data from a shapefile into my model/database and I have a separate model that has a PointField. I am trying to find all of the points in a polygon area but I can't figure out why my queries are returning empty.
class Neighborhood(models.Model):
boroname = models.CharField(max_length=13)
borocode = models.IntegerField()
countyFIPS = models.CharField(max_length=3)
nta_code = models.CharField(max_length=4)
nta_name = models.CharField(max_length=75)
shape_leng = models.FloatField()
shape_area = models.FloatField()
mpoly = models.MultiPolygonField(srid=4326)
objects = models.GeoManager()
other model:
class WayPoint(models.Model):
complaint = models.ForeignKey('Complaint')
geometry = models.PointField(srid=4326)
objects = models.GeoManager()
I have tried a few different things, including following the tutorial directions and manually typing in a Point that should definitely return something, but everything I try returns nothing.
In my view I have:
points = WayPoint.objects.all()
for point in points:
pt = point.geometry #so this gets the PointField
pts = Neighborhood.objects.filter(mpoly__contains=pt)
...and I get zero results for every WayPoint.
I have also tried(from the tutorial):
pnt_wkt = 'POINT(-73.3385 40.7245)'
obj = Neighborhood.objects.filter(mpoly__contains=pnt_wkt)
Nothing.
I've gone through the tutorial a few times and I can't figure out what I am doing wrong. I am new to GIS and am having trouble trying to troubleshoot the issue.
Ultimately I am trying to loop through and get all of the WayPoints in each Neighborhood, which I will eventually put on a map. But I can't even get any of my Neighborhood queries to return anything.
I feel like I must be missing something obvious here...
Edit: I went through the tutorial again and did it exactly with the WorldBorder dataset and tried my queries against that. My data set is for neighborhoods in NYC, so the point I'm using that definitely should return a polygon is a point in Times Square. When I query the neighborhood dataset I get an empty set, and I have the World Dataset at least returning back United States now. I don't understand why the neighborhood dataset is returning nothing.