开发者

Unreadable data in Mysql from a GeoDjango PointField

开发者 https://www.devze.com 2023-01-11 15:36 出处:网络
I\'m using GeoDjango with MySQL. I use a models.PointField(srid=4326) object, all works fine, the data is correctly saved and retrieved from the database, but when I do a select * from table from开发者

I'm using GeoDjango with MySQL. I use a models.PointField(srid=4326) object, all works fine, the data is correctly saved and retrieved from the database, but when I do a select * from table from开发者_Python百科 MySQL command line, data of PointField field shows unreadable characters, instead of a POINT(x,y) form, as I expected.

Is it a normal behavior?


Yes, that is normal. The data is stored in a binary format.

Try select AsText(geom) from table where 'geom' is the name of your geometry column.


you can use ST_AsText for storing points

mysql> SELECT ST_Y(Point(56.7, 53.34));
+--------------------------+
| ST_Y(Point(56.7, 53.34)) |
+--------------------------+
|                    53.34 |
+--------------------------+
mysql> SELECT ST_AsText(ST_Y(Point(56.7, 53.34), 10.5));
+-------------------------------------------+
| ST_AsText(ST_Y(Point(56.7, 53.34), 10.5)) |
+-------------------------------------------+
| POINT(56.7 10.5)                          |
+-------------------------------------------+

you can refer to the link for more detail: https://dev.mysql.com/doc/refman/8.0/en/gis-point-property-functions.html

0

精彩评论

暂无评论...
验证码 换一张
取 消