I have a bunch of points (lat+lon coordinates). Each one has a weight. I would like to get a weighted mean centroid of the points, taking into account the spheroid (as my points are scattered across the United States and I want to roughly adjust for the curvature of the earth).
Say I have these data in R:
pts <- data.frame(x=c(-100.5, -98.6, -98), y=c(35, 41, 44), weight=c(20, 15, 100))
How can I take these points and find what I am looking for?
I do not understand sp, sf, etc. very well. But based on this post (Finding centroid of cluster of points using R in particular the answer by @Ian Turton and @whuber's comment), it appears that we need to do these steps (which I am not really sure how to do):
- Convert the points to
spor something similar - Go from lat+lon to a 3d projection (geocentric coordinates). (Possibly using @whuber's answer to this question? Euclidean and Geodesic Buffering in R)
- Take the weighted average (mean) of the points. This produces the weighted centroid.
- Convert the weighted centroid back into latitude and longitude.
st_distance()andnngeo::st_nn()? – dimfalk Aug 24 '22 at 20:19