0

I have a Django model with the following field:

class PropertyPost(models.Model):
...
    location=models.PointField(null=True,blank=True)
...

I am filtering the objects.locations in PgAdmin against a user provided polygon then I would have only points in the polygon as follows:

select propertypost_propertypost.*
From propertypost_propertypost
where st_contains(
  St_SetSRID( 
         'POLYGON((1616523 -172630,1618559 -170395,1612691 -169037,1610057 -170554,1609857 -175464,1611294 -176382,1616523 -172630))'::geometry,
          3857),
  propertypost_propertypost.location)

this gives me 3 outputs as the result. Then in my django app I use the following view to do the same filtering:

class PropertyPostList(generics.ListCreateAPIView):
...
     def get_queryset(self):
        polystr = self.request.query_params.get('poly', None)
        if polystr:
            poly = GEOSGeometry('SRID=4326;' + polystr)
            qs = PropertyPost.objects.filter(location__contained=poly)
            return qs

now when I pass the following request it returns 4 results, which include the previous 3 results plus one more:

http://127.0.0.1:8000/prop-posts/?poly=POLYGON((1616523%20-172630,1618559%20-170395,1612691%20-169037,1610057%20-170554,1609857%20-175464,1611294%20-176382,1616523%20-172630))

I was wondering why this two different query gives different results, are they actually different?

  • Boundary conditions are always produced by code implementations. The touches property is always tricky. – Vince Mar 2 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.