Reputation: 443
Good morning,
inside my django-application I have a second database (which I can only read from, so not my own) that's build into my settings.py.
One of the columns has point-coordinates like...
POINT (390002.1610814564 6001433.406049595)
When selecting the data from db with...
try:
with connections['db_second'].cursor() as cursor:
cursor.execute("SELECT * from ...")
row = cursor.fetchall()
except Exception as e:
cursor.close()
...this data get's converted into...
0101000020E964000022936245FEDA1741A4A29D5E0DE85641
Does anyone know how to stop this (auto)converting? Or do I have to convert this data manually back into the needed coordinate-system? And if so: does anyone know how this convertion-type is called?
Note:
The data comes from a postgres-db.
Thank you for all your help and have a great day!
Upvotes: 1
Views: 216
Reputation: 5622
This is Well-Known Binary (WKB) format, compared to your expected Well-Known Text (WKT). Postgis (the Postgresql extension that manages spatial data) is able to do the translation from one format to another, so you can write your query like so:
SELECT ST_AsText(geometry) as geometry_wkt
FROM ...
I am not aware of any automatic way to do this in django, but with the keywords you may be able to find it by yourself.
Also note that you do not have to write SQL queries by hand, using Geo-Django you can add a PointField
to your model and make django-like queries. See:
https://docs.djangoproject.com/en/3.1/ref/contrib/gis/tutorial/
Upvotes: 1