gpt4 book ai didi

python - 在 python 与 st_project 中计算一个点

转载 作者:行者123 更新时间:2023-11-28 18:14:31 25 4
gpt4 key购买 nike

如您所见,我正在尝试在 Python 中实现函数 st_project。但是,我没有得到与函数 st_project 相同的结果

import geopy as g 
import geopy.distance as gp
from geopy.units import radians

start = g.Point(27.725778916300465,35.201911926269524)
distance = g.distance.VincentyDistance(meters = 50)
result = distance.destination(start, radians(90))

输出:Point(27.72574882153389, 35.29318076870505, 0.0)

但是,当执行 st_project 时,我得到以下结果

SELECT ST_AsText (
ST_PROJECT(
(SELECT SET_SetSRID(
ST_POINT(27.725778916300465,35.201911926269524),
4326)),
50,
radians(90)
)
);

输出:Point(27.7263279818659 35.2019119250247)

有什么想法可以得到准确的结果吗?

最佳答案

发生这种情况是因为 ST_Point 期望“x 坐标”作为它的第一个参数,即经度(假设 EPSG 4326),而 Point geopy 的 code> 构造函数将纬度作为其第一个参数。此外,destination 方法 expects以度为单位的方位角(与需要弧度的 ST_Project 相反)。

因此,如果您这样做:

SELECT ST_AsText (
ST_PROJECT(
(SELECT ST_SetSRID(
ST_POINT(35.201911926269524,27.725778916300465),
4326)),
50,
radians(90.0)
)
);

你得到:

                st_astext
------------------------------------------
POINT(35.2024189755536 27.7257789153716)
(1 row)

和:

import geopy as g 
import geopy.distance as gp
from geopy.units import radians

start = g.Point(27.725778916300465,35.201911926269524)
distance = g.distance.VincentyDistance(meters = 50)

result = distance.destination(start, 90) #no radians here
print(result.longitude, result.latitude)

你得到一个一致的结果:

35.202418975487014 27.725778915371617

关于python - 在 python 与 st_project 中计算一个点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49364812/

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