I am newbie to Django and developing a REST API using Django Rest Framework (DRF) and GIS. Previously, I was using an SQL query for transforming a geometry:
select
id,
name,
round(value::numeric, 2) as value,
st_transform(geometry, 3857) as geometry
from
my_model
...
class MyModel(models.Model):
name = models.CharField(max_length=50, blank=True)
value = models.FloatField()
geometry = models.GeometryField(null=True, blank=True)
class Meta:
db_table = u'my_model'
def __unicode__(self):
return '%s' % self.name
Here serializer class:
class MyModelSerializer(serializers.GeoModelSerializer):
class Meta:
model = MyModel
fields = ('id', 'name', 'value', 'geometry')
I have also tried to do this way but cannot transform output
class MyModelViewSet(viewsets.ModelViewSet):
queryset = MyModel.objects.all().transform(3857)
serializer_class = MyModelSerializer
How can I do this in Django Rest Framework and GIS? Where can I get query sample or a comprehensive tutorial for DRF?