PostgreSQL 几何类型
我对 postgres 的几何函数有疑问。基本上我有一个存储在 postgres 数据库中的多边形类型,我想检查我拥有的点是否位于该多边形内。 Postgres 为此有一个内置函数,但我在语法上遇到了一些问题。实际上,它不应该那么难弄清楚,但我希望这里有人以前使用过这些函数,或者只是碰巧知道。一般来说,我对 SQL 有点陌生,所以这可能只是一些一般性问题。
I am having a problem with postgres' geometric functions. Basically I have a polygon type stored in a postgres database and I want to check if a point that I have is located within this polygon. Postgres has a built-in function for this, but I'm having a bit of trouble with the syntax. Really it shouldn't be that hard to figure out but I'm hoping someone here has either worked with these functions before, or just happens to know. I'm somewhat new to SQL in general so it might just be some generic problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文档中有一个示例,请参阅 http://www. postgresql.org/docs/9.1/static/functions-geometry.html,表 9-30。
至于语法,您可能正在寻找类似的东西
There is an example of this in the documentation, see http://www.postgresql.org/docs/9.1/static/functions-geometry.html, table 9-30.
As for the syntax, you are probably looking for something along the line of
ST_Contains 可以与 st_geomfromtext 结合使用来确定您的点是否位于该多边形中。我有一个表,其中“poly”列包含一个多边形,另一个表包含要检查的纬度/经度值列表是否在该多边形内。您将保存多边形的表连接到保存 1=1 上的列表的表(在返回的每行上提供纬度/经度/多边形),然后构建 st_ 语句。
这需要定义的点并检查它是否在多边形中(我将我的点称为“多边形”)。如果该点位于该多边形内,则返回“t”。
这需要一个纬度和经度值并将其转换为一个点。
将两者放在一个 where 子句中:
那么这只是构建 select 子句的问题...我可以提供帮助,但您忽略了问题中的模式。
ST_Contains can be used in conjunction with st_geomfromtext to determine if your point is in that polygon. I have a table with the column 'poly' holding a polygon and another table with list of lat/lon values to check are within that polygon. You join the table holding the polygon to the table holding the list on 1=1 (gives you lat/lon/poly on each line returned) and then build the st_ statements.
This takes the point defined and checks if it's in the polygon (I called mine 'poly'). It returns 't' if the point is within that polygon.
This takes a lat and lon value and translates it to a point.
Put the two together in a where clause:
Then it's just a matter of building out the select clause...I could help with that, but you neglect schema in your question.