I have a Place
model which has a polygon field:
from django.contrib.gis.db import models
class Place(models.Model):
area = models.PolygonField()
I want to translate the area
field of an instance of this Place
model.
Here is how I am doing it right now:
from django.contrib.gis.db.models.functions import Translate
place = Place.objects.get(pk=1)
place.area = Place.objects.filter(pk=place.pk).annotate(new_area=Translate('area', 0.001, 0.001)).first().new_area
place.save()
This seems very hacky. I think that there should be a way of doing this in the following way:
place = Place.objects.get(pk=1)
place.area = Translate(place.area, 0.001, 0.001)
place.save()
But this throws an exception.
Should I be using some library? Which one works well with GeoDjango and its models/fields?
What is the better way of doing it?