使用R计算两点(纬度,经度)之间地理空间距离的函数 [英] Function to calculate geospatial distance between two points (lat,long) using R

查看:42
本文介绍了使用R计算两点(纬度,经度)之间地理空间距离的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有经纬度格式的地理编码点,我想使用 R 计算它们之间的距离.这看起来很简单,但我找不到可以轻松完成的函数.我一直在尝试用 gdistance 包来做这件事,但它看起来非常复杂并且面向图形,我只需要一个数字.distanceBetween(pointA,pointB) 之类的东西会返回一个数字.

I have geocoded points in long, lat format, and I want to calculate the distance between them using R. This seems pretty straight forward, yet I can't find a function that will do it easily. I've been attempting to do it with the gdistance package, but it seems very convoluted and oriented to graphing, I just need a number. Something like distanceBetween(pointA,pointB) that returns a number.

推荐答案

加载geosphere包可以使用很多不同的功能

Loading the geosphere package you can use a number of different functions

library(geosphere)
distm(c(lon1, lat1), c(lon2, lat2), fun = distHaversine)

还有:

distHaversine()
distMeeus()
distRhumb()
distVincentyEllipsoid()
distVincentySphere()

...

这篇关于使用R计算两点(纬度,经度)之间地理空间距离的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆