1

I have a Geo-Django project in which i am using postgres as database. I have a table with geometry column. I am filtering data and getting results which is working fine.

Problem is I want the geometry results in text form so i am trying to use ST_AsText in it. The Issue is I tried passing this function multiple ways and using annotations as well but I am not able to do that due to multiple errors.

As suggestion or successful implementation of applying ST_ functions would help me.

pointsArr = ScrapedArea.objects.filter(geom__intersects=poly).values('geom', 'url')

1 Answer 1

3

You need to convert it to a geosgeometry object before passing it into the query: https://docs.djangoproject.com/en/3.1/ref/contrib/gis/geos/

Then, use the annotate method with it:

>>> from django.contrib.gis.db.models.functions import Length
>>> Track.objects.annotate(length=Length('line')).filter(length__gt=100)

https://django.readthedocs.io/en/stable/ref/contrib/gis/functions.html

3
  • No its not about the geometry being sent in input. Its about the one coming as a result from query. Oct 25, 2020 at 15:45
  • Can you add an example of what you have attempted?
    – snowman2
    Oct 25, 2020 at 16:55
  • Added an example.
    – snowman2
    Oct 26, 2020 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.