【问题标题】:PostGIS - find circles a point is inside ofPostGIS - 找到一个点在里面的圆圈
【发布时间】:2017-06-13 22:31:52
【问题描述】:

我有一个游戏。玩家是点,物品是具有不同半径的圆。玩家可以添加物品。玩家还必须看到他们在范围内的物品。

  1. 添加物品后,很容易找到物品范围内的所有玩家。

  2. 当玩家移动时,我如何找到他们能看到的所有物品?

【问题讨论】:

    标签: geolocation postgis geo


    【解决方案1】:

    我不知道自己为什么会糊涂,答案当然是:

    ST_Within(geometry A , geometry B) 其中 A 是圆,B 是点。

    因此,给定一个以坐标 (0, 5) 为中心、半径为 50 且点位于 (3, 7) 的圆,查询将是:

    ST_Within(
      ST_BUFFER(ST_GeometryFromText('POINT(0 5)'), 50),
      ST_GeometryFromText('POINT(3 7)'))
    

    【讨论】:

    • 使用ST_DWithin 代替ST_Within + ST_Buffer:ST_DWithin(ST_GeometryFromText('POINT(0 5)'), ST_GeometryFromText('POINT(3 7)'), 50)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多