Postgis几何条件

问题描述 投票:1回答:1

我有一张桌子:

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功能?

sql postgresql postgis
1个回答
1
投票

首先,你不需要在ST_MakePoint()中包装Geometry(),这是默认值。

你可以做两件事,

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

如果你想做后者,ST_DWithin是超级简洁的。它在第一个输入周围创建了一个bugger,并查找ST_Within第二个输入的所有内容。

ST_DWithin(geom, geom, radius);

你还能想要什么?

如果你想测试二进制相等,那么=可以正常工作。但是,您需要进行舍入错误,并且需要与它们一样精确,以便获得相同的EKWT。

© www.soinside.com 2019 - 2024. All rights reserved.