I am creating grid over Jingsu province with r-package(sp) makegrid function. I want to calculate distance between each grid centre and waterbenthos sampling site, but the unit of longitude and latitude of grid are metres, and the unit of longitude and latitude of waterbenthos are decimal degrees. Question: how can I convert metres to decimal degree? so i can calculate their diatance.
I've tried to search on the internet for a few days, still can't solve this problem. Your answer is greatly appreciated!
library(sp)
library(rgdal)
Yixing <- readOGR(dsn = "D:/Data_R_afu/yixing", layer = "boundary")<br/>
grid <- makegrid(Yixing, cellsize = 1000) # cellsize in map units!<br/>
grid <- SpatialPoints(grid, proj4string = CRS(proj4string(Yixing)))<br/>
grid@coords<br/>
# x1 x2<br/>
#[1,] 13311000 3627100<br/>
#[2,] 13311000 3628100<br/>
#[3,] 13312000 3628100<br/>
#[4,] 13313000 3628100<br/>
#...<br/>
#...<br/>
#...<br/>
waterbenthos<- readOGR(dsn = "D:/Data_R_afu/yixing", layer =
"afu_waterbenthos_r_ln(Rt+1Dg+1)")<br/>
waterbenthos@coords<br/>
# coords.x1 coords.x2<br/>
#[1,] 119.8853 31.37628<br/>
#[2,] 119.8853 31.37628<br/>
#[3,] 119.8853 31.37628<br/>
#[4,] 119.9273 31.40567<br/>
#...<br/>
#...<br/>
#...<br/>
#proj4string :
# [+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs+ellps=WGS84 +towgs84=0,0,0]
– afuya Oct 12 '19 at 01:40
#colnames(WindowCentroid) <- c("CentroidX","CentroidY")
#x1=c(0,0)
#x2=c(3,4)
#EuclideanDistance <- function(x1, x2) sqrt(sum((x1 - x2) ^ 2))
#euc.dist <- c()
#Radius = 2
#WindowCentroidIndex = data.frame(NA, ncol = 2) – afuya Oct 12 '19 at 07:58