3

I'm trying to get N points within 5000 meters of a certain point. My database is Postgres(PostGis). I have a model like this:

class Theatre(models.Model):
    geom = models.PointField(srid=4326, blank=True, null=True, default=None)
    objects = models.GeoManager()

Then I ran a couple lines in django shell:

Theatre.objects.filter(geom__dwithin=(GEOSGeometry('POINT(30.111199 -97.309990)'), D(m=5000)))

and I get error:

ValueError: Only numeric values of degree units are allowed on geographic DWithin queries.

I found the document in here and it says calculating the geometry distance..

Please help.. Thanks very much!!

odieatla
  • 1,049
  • 3
  • 15
  • 35

2 Answers2

1

A little late to the party, but...

According to Django's source code this error will be raised if using PostGIS and the field you are querying against is "geodetic" (its SRID corresponds with a coordinate system that uses non-projected units (e.g., latitude/longitude) (definition from the docs) -- in which case you need to pass a numeric value of degree units instead of the D object, as indicated by the error message.

This is unfortunately not a simple conversion depending on the distance from the equator; see How do I convert kilometres to degrees in Geodjango/GEOS?

DrMeers
  • 4,117
  • 2
  • 36
  • 38
-2

It looks like you x and y values in the POINT WKT are reversed.

Try:

Theatre.objects.filter(geom__dwithin=(GEOSGeometry('POINT(-97.309990 30.111199)'), D(m=5000)))
garnertb
  • 9,454
  • 36
  • 38