-1

I have a dataset of unit and lat-long coordinates. I would like to generate spatial a spatial weighting matrix. Automatically I have generated that matrix but I do not custom how far two points are closed enough for the software to decide that there is contiguity. Problem: I would like to generate different weighting matrices depending to the threshold i will consider as criteria of closedness. for example four points A(2,547; -5,7654), B(3,768; -5,2398), C(2,569; -6,6509), D(1,568; -7,6709). first I would like to generate distance matrix in kilometers second define a contiguity matrix depending to the radius i will choose

Thanks for your help in Python

Best

1 Answers1

0

Maybe you can try distm from geosphere package to create the distance matrix like below

> distm(df[-1],df[-1])/1000
         [,1]     [,2]     [,3]     [,4]
[1,]   0.0000 147.2548  97.9553 236.8985
[2,] 147.2548   0.0000 204.8782 362.6241
[3,]  97.9553 204.8782   0.0000 157.9538
[4,] 236.8985 362.6241 157.9538   0.0000

Data

df <- structure(list(id = c("A", "B", "C", "D"), Lon = c(2.547, 3.768, 
2.569, 1.568), Lat = c(-5.7654, -5.2398, -6.6509, -7.6709)), class = "data.frame", row.names = c(NA,
-4L))
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81