gpt4 book ai didi

sql - Postgis 几何 where 条件

转载 作者:行者123 更新时间:2023-11-29 12:51:50 28 4
gpt4 key购买 nike

我有一张 table :

create table if not exists places(
id bigserial not null constraint places_pkey primary key,
location geography(Point,4326));

一行:

INSERT INTO places (id, location) VALUES
(1, Geography(ST_MakePoint(14.582045, 46.08060333)));

我想在表格中查询确切位置。我可以这样做:

select * from places where ST_DWithin(Geography(ST_MakePoint(14.582045, 46.08060333)), location, 0);

但肯定有更简洁的方法来做到这一点,比如:

select *
from places
where location = Geography(ST_MakePoint(14.582045, 46.08060333))

也许是 ST_Equals 或其他一些 postgis 函数?

最佳答案

首先,您不需要将 ST_MakePoint() 包装在 Geometry() 中,这是默认设置。

有两件事你可以做,

  1. 检查点是否存在,
  2. 检查范围内是否存在点。

如果你想做后者,ST_DWithin 非常简洁。它围绕第一个输入创建了一个窃听器,并查找 ST_Within 第二个输入的所有内容。

ST_DWithin(geom, geom, radius);

您还想要什么?

有了相等性,如果你想测试二进制相等性,= 工作正常。但是,您会受到舍入误差的影响,并且您需要对它们都保持精确,以便获得相同的 EKWT。

关于sql - Postgis 几何 where 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52217620/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com