【发布时间】:2014-12-31 20:10:56
【问题描述】:
我尝试了以下 SQL 命令:
CREATE TABLE places(
lat_lng geography(Point,4326),
place_name varchar(50)
);
CREATE INDEX places_lat_lng_idx ON places USING gist(lat_lng);
INSERT INTO places values ('POINT(-126.4 45.32)', 'Food Bar1');
INSERT INTO places values ('POINT(-126.4 47.32)', 'Food Bar2');
INSERT INTO places values ('POINT(-125.4 47.42)', 'Food Bar3');
SELECT place_name, ST_AsText(lat_lng) as point
FROM places WHERE places.lat_lng &&
ST_MakeEnvelope(-130.0, 44.0,
-100.0, 46.7, 4326);
结果是:
place_name | point
------------+---------------------
Food Bar1 | POINT(-126.4 45.32)
Food Bar2 | POINT(-126.4 47.32)
Food Bar3 | POINT(-125.4 47.42)
这对我来说看起来不正确,因为 ymax 是 46.7,但是“Food Bar2”和“Food Bar3”的 ymax 值分别为 47.32 和 47.42。问题出在哪里?
【问题讨论】:
-
使用 ST_Intersects 或 ST_Contains 代替 &&。
标签: postgresql geospatial postgis