python postgis ST_Contains 失败的查询

发布于 2024-12-21 17:55:29 字数 455 浏览 1 评论 0原文

我一直在尝试以下操作,但总是失败,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

场罚期间 2024-12-28 17:55:29

可能是一个简单的答案...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

请帮我爱他 2024-12-28 17:55:29

这与 python 运算符有关。我正确使用 python % 运算符输入了所有 sql 参数,并且它有效。像这样,

roomTypeSQL = "SELECT spftype FROM cameron_toll_spatialfeatures WHERE ST_Contains(ST_GeomFromText(%s),ST_geomFromWKB(geometry))=%s;"

roomTypeData = (pointTested,'t') # "POINT(-3.164005 55.926378)"

.execute(roomTypeSQL, roomTypeData)

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,

roomTypeSQL = "SELECT spftype FROM cameron_toll_spatialfeatures WHERE ST_Contains(ST_GeomFromText(%s),ST_geomFromWKB(geometry))=%s;"

roomTypeData = (pointTested,'t') # "POINT(-3.164005 55.926378)"

.execute(roomTypeSQL, roomTypeData)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文