ST_MakeEnvelope 和 Google 地图坐标问题
ST_MakeEnvelope with Google Maps Coordinates problem
在 postgress 中,我有以下函数使用 ST_MakeEnvelope
基于 Google 将视口坐标映射到 returns 该视口内的所有项目。
CREATE OR REPLACE FUNCTION public.search_projects_area(
lngw double precision,
lats double precision,
lnge double precision,
latn double precision
) RETURNS SETOF project_locations LANGUAGE sql STABLE AS $ function $
SELECT
A.*
FROM
project_locations A
WHERE
st_intersects(
A.location :: geography,
ST_MakeEnvelope(lngw, lats, lnge, latn, 4326) :: geography
) $ function $
下面是我如何获取创建信封的坐标:
const bounds = this.map.getBounds();
const sw = this.map.getBounds().getSouthWest();
const ne = this.map.getBounds().getNorthEast();
const lngw = sw.lng();
const lats = sw.lat();
const lnge = ne.lng();
const latn = ne.lat();
问题是有时无法获取特定区域的项目,这取决于我将地图缩放或定位到的位置。尽管在所有情况下,项目都在视口内。
好像 ST_MakeEnvelope
方法没有根据地图视口创建正确的矩形。
我上面的代码正确吗?
通过转换为 geography
,边界框边缘是使用大圆弧而不是直线创建的。因此,看起来在视口(投影在 3857 中)内的点可能在框外。
因此,要么您确实想要使用大圆弧并且这是一个显示问题,要么您想要坚持显示的内容并且您需要删除对 geography
[=12= 的强制转换]
在 postgress 中,我有以下函数使用 ST_MakeEnvelope
基于 Google 将视口坐标映射到 returns 该视口内的所有项目。
CREATE OR REPLACE FUNCTION public.search_projects_area(
lngw double precision,
lats double precision,
lnge double precision,
latn double precision
) RETURNS SETOF project_locations LANGUAGE sql STABLE AS $ function $
SELECT
A.*
FROM
project_locations A
WHERE
st_intersects(
A.location :: geography,
ST_MakeEnvelope(lngw, lats, lnge, latn, 4326) :: geography
) $ function $
下面是我如何获取创建信封的坐标:
const bounds = this.map.getBounds();
const sw = this.map.getBounds().getSouthWest();
const ne = this.map.getBounds().getNorthEast();
const lngw = sw.lng();
const lats = sw.lat();
const lnge = ne.lng();
const latn = ne.lat();
问题是有时无法获取特定区域的项目,这取决于我将地图缩放或定位到的位置。尽管在所有情况下,项目都在视口内。
好像 ST_MakeEnvelope
方法没有根据地图视口创建正确的矩形。
我上面的代码正确吗?
通过转换为 geography
,边界框边缘是使用大圆弧而不是直线创建的。因此,看起来在视口(投影在 3857 中)内的点可能在框外。
因此,要么您确实想要使用大圆弧并且这是一个显示问题,要么您想要坚持显示的内容并且您需要删除对 geography
[=12= 的强制转换]