查询查找点列与 PostGis 中的点之间的距离
我在我的应用程序中使用 PostGis 进行基于位置的计算。在表中,我有一列地理类型为“位置”的列(点(经纬度))...就像表中存在的行数一样。 我想通过一个点(点(经纬度))并检查该点(我通过的)与所有行中的位置列之间的距离....如果距离小于 5 m....它将返回名称如何查询这一点。
I am using PostGis for Location based calculations in my Application. In a Table i have a column called 'location' in geography type(Point(lon lat))...Like this number of rows present in the Table.
I want to pass a point(Point(lon lat)) and check distance between this point(i passed) and location column in all rows....and if distance is less than 5 m....it will return the name of the point.How to query this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您的数据 srid 是 4326,您要查找的查询是:
请注意,ST_DWithin 中的单位(0.0008)与您的投影单位相同,在 4326 情况下,它们是度。如果您的投影数据以米为单位,您将能够使用米。
对于生产应用程序,您应该使用几何类型,速度更快。来自 stackoverflow 上一个问题:
Assuming that your srid of your data is 4326 the query you are looking for is:
Note that the units(0.0008) in ST_DWithin are in the same units of your projection, in the 4326 case they are degrees. If your projection data is in meters, you will be able to use meters.
For a production application you should use geometry types, is faster. From a stackoverflow previous question:
太好了,谢谢。它在数据库中运行良好。我有以下来自 PHP 的代码..它返回类似,查询失败:
$locationresult=pg_query($con,"SELECT id,name FROM gps.locationnames WHERE ST_DWithin(location,ST_GeographyFromText('POINT(lon lat)'),500)") or die ('查询失败:'.pg_last_error($con ));
这里有什么问题..
Great.Thank You. It works fine in database. I have following code from PHP..it returs like, Query Failed:
$locationresult=pg_query($con,"SELECT id,name FROM gps.locationnames WHERE ST_DWithin(location,ST_GeographyFromText('POINT(lon lat)'),500)") or die ('Query Failed:'.pg_last_error($con));
What is the problem here..