gpt4 book ai didi

javascript - 计算 2 个纬度/经度之间道路折线上的距离

转载 作者:行者123 更新时间:2023-11-29 04:10:23 27 4
gpt4 key购买 nike

这不是乌鸦飞的距离。

我正在寻找这样的 API:

distanceMiles = calculateMilesBetweenPointsAlongRoad(LatLon1, LatLon2, RoadPolyline)

我有一条表示为折线的道路。

当车辆在这条路上行驶时,我会捕捉纬度/经度。我想计算车辆在每个报告的 LatLon 之间行驶的距离。

由于数据摄取的速度,我想在没有空间查询的情况下执行此操作,但如果唯一的方法是将道路多段线存储在 BigQuery 或 PostGIS 中并持续对其进行查询,我会接受。

最佳答案

As a vehicle moves on road, I capture lat/lons. I want to calculate the distance the vehicle traveled between each reported LatLon.

让我用 2017 年玛丽亚飓风计算距离的场景来模拟您的用例

下面查询为此(BigQuery 标准 SQL)“准备”数据:

#standardSQL
WITH points AS (
SELECT ROW_NUMBER() OVER(ORDER BY iso_time) pos,
ST_GEOGPOINT(longitude, latitude) AS point
FROM `bigquery-public-data.noaa_hurricanes.hurricanes`
WHERE name LIKE '%MARIA%' AND season = '2017'
AND ST_DWITHIN(ST_GEOGFROMTEXT('POLYGON((-179 26, -179 48, -10 48, -10 26, -100 -10.1, -179 26))'), ST_GEOGPOINT(longitude, latitude), 10)
), lines AS (
SELECT pos, ST_MAKELINE(LAG(point) OVER(ORDER BY pos), point) line
FROM points
)
SELECT pos, line
FROM lines
WHERE pos > 1

上面可以可视化为

enter image description here

现在,下面计算飓风“行进”的距离

#standardSQL
WITH points AS (
SELECT ROW_NUMBER() OVER(ORDER BY iso_time) pos,
ST_GEOGPOINT(longitude, latitude) AS point
FROM `bigquery-public-data.noaa_hurricanes.hurricanes`
WHERE name LIKE '%MARIA%' AND season = '2017'
AND ST_DWITHIN(ST_GEOGFROMTEXT('POLYGON((-179 26, -179 48, -10 48, -10 26, -100 -10.1, -179 26))'), ST_GEOGPOINT(longitude, latitude), 10)
), lines AS (
SELECT pos, ST_MAKELINE(LAG(point) OVER(ORDER BY pos), point) line
FROM points
)
SELECT SUM(ST_LENGTH(line)) path_length
FROM lines
WHERE pos > 1

enter image description here

注意:ST_LENGTH(geography_expression) 返回输入 GEOGRAPHY 中线的总长度(以米为单位)

您可以阅读有关 ST_LENGTH here 的更多信息

关于javascript - 计算 2 个纬度/经度之间道路折线上的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55428292/

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