PostgreSQL + GeoDjango:更好地理解 POINTS 是如何翻译的
大家好 Stackoverflow,
我无法理解 GeoDjango 中的 POINT 引用如何转换为查询语句。
jpic的建议帮助我捕获了查询语句控制台,但打印输出对我来说没有任何意义。
在我的 view.py 函数(保存表单)中,我有以下行:
savedProject.geolocation = GEOSGeometry('POINT(%s %s)' %(u_lng,u_lat))
u_lng 和 u_lat 作为用户协调(取自会话信息)。 u_lat 和 u_lng 是小数形式的度值。
但是,当我按照建议检查 sql 语句时,我发现 POINT 已转换为
ST_GeomFromEWKB(E'\001\001\000\000 \346\020\000\000\352\036~\243\302\256H\300\352X\245\364L\3515\300'::bytea)
sql 语句中的内容,并且被 sql 拒绝并显示错误消息
ERROR: invalid byte sequence for encoding "UTF8": 0x00
使用 GeoDjango 将 lng、lat 点转换为 postgis 的正确方法是什么?
感谢您帮助我们更好地了解此事!
Hi Stackoverflow people,
I am having trouble to understand how POINT references in GeoDjango are translated to query statements.
jpic's advice helped me very much to capture the query statements in the console, but the print out does not make any sense to me.
In my view.py function (saving the form), I have the following line:
savedProject.geolocation = GEOSGeometry('POINT(%s %s)' %(u_lng,u_lat))
with u_lng and u_lat as the user coordinated (taken from the session information). u_lat and u_lng are degree values as decimals.
However when I check the sql statement as suggested, I see that the POINT was translated to
ST_GeomFromEWKB(E'\001\001\000\000 \346\020\000\000\352\036~\243\302\256H\300\352X\245\364L\3515\300'::bytea)
in the sql statement and which is rejected by sql with the error message
ERROR: invalid byte sequence for encoding "UTF8": 0x00
What is the correct way to translate lng, lat points into postgis with GeoDjango?
Thank you for your help to understand this matter better!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我远非这方面的专家。但我曾经编写过一些代码,使用 Django 在 postgis 数据库中保存了某个点。
我这样做的方法是:
I'm far from an expert on the subject. But I've once written some code that saved a certain point in postgis database using Django.
The way I did it was:
看来错误消息源于
确切问题的解释中的一个小错误,可以在这里找到补丁:
我有修补adapter.py中的四行,错误就消失了。
感谢您的帮助!
It seems that the error message originates from a little bug in
Explanations for the exact problem and the patch can be found here:
I have patch the four line in the adapter.py and the error is gone.
Thank you for all your help!