r - 在R中计算大圆距离
问题描述
过去,在 MATLAB 中,我使用大圆距离计算计算了给定其纬度和经度的点的索引。我会和你分享我的代码。我对 R 中的等效函数会是什么样子或者 on 是否存在感到困惑?我找到了一些显示两点之间距离的代码,但没有一个代码可以帮助我索引我的数据。
这是我的 MATLAB 代码!
%% Define latlon grid and coordinates (lon follows lat)
lon_grid = transpose([40.1 40.12 40.14; 40.3 40.32 40.34; 40.5 40.52 40.54]);
lat_grid = transpose([30 30.2 30.4;30.02 30.22 30.42; 30.04 30.24 30.44]);
coord = [30.4125 40.4043];
%% Compute great circle distance
dist = distance('gc',coord(1),coord(2),lat_grid,lon_grid);
%% Retrieve index of minimum distance
[value,array_index] = min(distance(:));
[i,j] = ind2sub(size(dist),array_index);
“dist”计算是这里的派对作品。您应该能够使用提供的代码来重现结果并查看我希望在 R 中实现的目标。
同样,在 R 中可能会给出一个可比较的函数,我有以下内容: 纬度点网格 经度点网格 两个点,以度为单位,表示我所在位置的纬度和经度。
解决方案
也许这有效:
library(geoshpere)
dist<-apply(coord, 1, FUN=function(p) distHaversine(p, lonlat_matrix))
推荐阅读
- hyperledger-fabric - 如何在 Hyperledger Fabric GO 中执行注销操作?
- mysql - 如何使用 mysql-client 从 mac 连接到 mysql url
- python - 如何有效地将功能应用于大熊猫数据框的行?
- django - 如何为 Django 单例模型修复“名称‘自我’未定义”
- reactjs - this.setState 不会触发组件中的重新渲染
- solr - 在云模式下运行 Solr 自定义过滤器
- c# - dc.BeginDialogAsync:“值不能为空。\n参数名称:选项”
- python - 无法用 seaborn 地块来评估斧头对象
- python - 如何自动复制 - 粘贴 - 运行 .exe 文件?
- javascript - 带有数组值的jQuery排序元素没有html属性