python postgis ST_Contains 失败的查询
我一直在尝试以下操作,但总是失败,
roomTypeSQL = "SELECT spftype FROM cameron_toll_spatialfeatures WHERE ST_Contains(ST_GeomFromText(%s), ST_geomFromWKB(geometry)) = 'True';"
roomTypeData = (pointTested) # "POINT(-3.164005 55.926378)"
.execute(roomTypeSQL, roomTypeData)
我想从包含特定点的表中获取多边形。我也尝试过 ST_Within ,但也失败了。我认为我的问题与点和多边形的格式有关,但我尝试了几乎所有组合,但没有任何效果。我尝试定义我的多边形并且它有效,但我必须使用数据库中的多边形来完成它。我的 postgresql 日志文件也不是特别有用。 有人能看出有什么问题吗? 提前致谢!
I have been trying the following but always fails,
roomTypeSQL = "SELECT spftype FROM cameron_toll_spatialfeatures WHERE ST_Contains(ST_GeomFromText(%s), ST_geomFromWKB(geometry)) = 'True';"
roomTypeData = (pointTested) # "POINT(-3.164005 55.926378)"
.execute(roomTypeSQL, roomTypeData)
I want to get the polygon from my table which contains the specific point. I have also tried ST_Within
which also fails. I think my problem is related to the formatting of the point and polygon but I have tried almost all combinations and nothing does the job. I tried defining my polygon and it worked but I must do it with a polygon from the database. My postgresql log file is not particularly helpful either..
Can anybody see anything going wrong?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能是一个简单的答案...st_contains 返回“t”而不是“true”。 Postgres 对大写敏感,请确保不是 T
might be a simple answer...st_contains returns 't' not 'true'. Postgres is cap sensitive, make sure t not T
这与 python 运算符有关。我正确使用 python % 运算符输入了所有 sql 参数,并且它有效。像这样,
Python 运算符有时会非常令人沮丧。它并不总是按预期工作。我有一些 SQL 命令的示例,其中我必须将参数直接放在 SQL 命令中。尽管在 Python 文档中不建议使用此方法,但此方法有效。
This had to do with python operators. I entered all the sql arguments using the python % operator properly and it worked. Like this,
The python operator can be quite frustrating sometimes. It doesn't always work as expected. I have some examples of SQL commands in which I had to place the arguments directly inside SQL commands. This method worked although its not advisable in Python documentation.