geosphere

Using the geosphere distm function on a data.table to calculate distances

帅比萌擦擦* 提交于 2019-11-27 07:44:35
问题 I've created a data.table in that has 6 columns. My data.table has a columns compairing two locations: Location 1 and Location 2. I'm trying to use the distm function to calculate the distance between the locations on each row, creating a 7th column. The distm package in the geosphere package requires two different vectors for each lat/long combo to be calculated against. My code below does not work, so I'm trying to figure out how to provide vectors to the function. LOC_1_ID LOC1_LAT_CORD

find locations within certain lat/lon distance in r

眉间皱痕 提交于 2019-11-26 12:46:05
问题 I have a gridded dataset, with data available at the following locations: lon <- seq(-179.75,179.75, by = 0.5) lat <- seq(-89.75,89.75, by = 0.5) I would like to find all of the data points that are within 500 km of the location: mylat <- 47.9625 mylon <- -87.0431 I aim to use the geosphere package in R, but the method I\'ve currently written does not seem very efficient: require(geosphere) dd2 <- array(dim = c(length(lon),length(lat))) for(i in 1:length(lon)){ for(ii in 1:length(lat)){ clon