postgresql postgis如果点在圆内 [英] postgresql postgis If point inside circle

查看:646
本文介绍了postgresql postgis如果点在圆内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PostgreSQL作为数据库,我有一个名为car_wash的表,其字段为"point geometry"(使用postgis),所以在应用程序中,我正在使用GOOGLE API从用户那里得到长期支持,下一步,我需要在周围创建圆圈用户,并检查我是否在此圈子内使用car_wash

I'm using postgresql as db , i have the table named car_wash with field "point geometry"(use postgis) so in application I'm getting lon lat from user using GOOGLE API, next step I need to create circle around user and check if car_wash inside this circle I use

  select *
 from car_wash cw
where
ST_DWithin (
   cw.lon_lat,
   ST_GeomFromText('POINT(54.21 22.54)')
)=false
AND
not cw.was_deleted

这是核心方式吗?如果需要,根据此查询,我的srid为0

Is it corect way? IF you need my srid is 0 according to this query

 Select Find_SRID('public',  'car_wash',  'lon_lat')

推荐答案

ST_GeomFromText('POINT(54.21 22.54)')的SRID必须与cw.lon_lat的SRID相同.假设cw.lon_lat的SRID为4326,则可以使用ST_GeomFromText('POINT(54.21 22.54)',4326)设置其他属性srib. 其次,ST_DWithin需要缓冲区距离作为第三个参数.因此,假设您要检查点是否在100米缓冲区内,应该是

SRID of the ST_GeomFromText('POINT(54.21 22.54)') must be same as the SRID of cw.lon_lat. Suppose SRID of cw.lon_lat is 4326 you can set the other attribute srib by using ST_GeomFromText('POINT(54.21 22.54)',4326). Secondly, ST_DWithin needs buffer distance as 3rd parameter. So suppose if you want to check if point is within 100 meter buffer it should be like

ST_DWithin (
   cw.lon_lat,
   ST_GeomFromText('POINT(54.21 22.54)', 3857), 100
)

缓冲区值取决于srid单位.如果是3857米您需要使用st_setSRID例如将cw.lon_lat和POINT(54.21 22.54)转换为相同的SRID,以使其正常工作.

Buffer value is according to the srid unit. in case of 3857 its meter. You need to convert cw.lon_lat and POINT(54.21 22.54) to the same SRID in order to make this work, using st_setSRID e.g.

这篇关于postgresql postgis如果点在圆内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆