Search code examples
geometrypostgisgeodjangogeography

How to use Geodjango snap_to_grid on geography Field (not geometry)


I create a table using geodjango with a column location = models.PointField(geography=True).

class Point(models.Model):
    location = models.PointField(geography=True)

Later I want to use ST_snapToGrid method to cluster those locations. But if I use

Point.objects.snap_to_grid(0.001)

I got an error:

function st_snaptogrid(geography, numeric) does not exist
LINE 1: SELECT (ST_SnapToGrid("app_point"."location",000.1)) AS...

This may be caused by the difference between geography and geometry. So how can I use snap_to_grid this method? Thanks!


Solution

  • you could not use Field.geography=True with snap_to_grid.

    e.g:

    class Point(models.Model):
        location = models.PointField(dim=2)