将具有相同坐标的点聚合在一个点中
aggregate the points that have same coordinates in one point
我有一个关于 R 中空间聚合的问题。我的数据集有 latitude/longitude 个坐标,有些坐标彼此靠近,有些则不是。我想为latitude/longitude个坐标相近的点加一分
我不确定该怎么做。我是否将 latitude/longitude 坐标列为组,并求平均值使一个点代表每个组?因为我对这类东西没有什么经验。我希望你们中的任何人都能找到一些有用的 guidance/a 可能的解决方案。
Time Received Speed Latitude Longitude
1.47917E+12 1.5 38.9295887 -77.2478945
1.47917E+12 1 38.9295048 -77.247922
1.47917E+12 3 38.9294865 -77.2479055
1.47917E+12 5 38.9294865 -77.2479055
1.47917E+12 2 38.9294771 -77.2478712
1.47917E+12 2 38.9294772 -77.2478712
1.47917E+12 1.5 38.9294771 -77.2477417
1.47917E+12 1.5 38.9294771 -77.2477417
例如,如果我可以将下面的 latitude/longitude 坐标作为一个点:
38.9294771 -77.2478712
38.9294772 -77.2478712
38.9294771 -77.2477417
38.9294771 -77.2477417
将在不影响时间和速度值的情况下像下面这样:
38.9294771 -77.24774117
您可以使用我在 找到的下面给出的函数将您的坐标四舍五入到任何需要的精度。在下面的示例中,我使用 0.1。
fakedata <- data.frame(time = 1:100,
speed = sample(3, 100, replace=TRUE),
latitude = seq(from=20, by=0.01, length.out=100),
longitude = seq(from=30, by=0.01, length.out=100))
round_any = function(x, accuracy, f=round){f(x/ accuracy) * accuracy}
library(dplyr)
fakedata %>%
mutate(latitude_round = round_any(latitude, accuracy = 0.1),
longitude_round = round_any(longitude, accuracy = 0.1))
然后使用 dplyr::group_by()
按您的舍入坐标分组,并根据需要汇总时间和速度值。
我有一个关于 R 中空间聚合的问题。我的数据集有 latitude/longitude 个坐标,有些坐标彼此靠近,有些则不是。我想为latitude/longitude个坐标相近的点加一分
我不确定该怎么做。我是否将 latitude/longitude 坐标列为组,并求平均值使一个点代表每个组?因为我对这类东西没有什么经验。我希望你们中的任何人都能找到一些有用的 guidance/a 可能的解决方案。
Time Received Speed Latitude Longitude
1.47917E+12 1.5 38.9295887 -77.2478945
1.47917E+12 1 38.9295048 -77.247922
1.47917E+12 3 38.9294865 -77.2479055
1.47917E+12 5 38.9294865 -77.2479055
1.47917E+12 2 38.9294771 -77.2478712
1.47917E+12 2 38.9294772 -77.2478712
1.47917E+12 1.5 38.9294771 -77.2477417
1.47917E+12 1.5 38.9294771 -77.2477417
例如,如果我可以将下面的 latitude/longitude 坐标作为一个点:
38.9294771 -77.2478712
38.9294772 -77.2478712
38.9294771 -77.2477417
38.9294771 -77.2477417
将在不影响时间和速度值的情况下像下面这样:
38.9294771 -77.24774117
您可以使用我在
fakedata <- data.frame(time = 1:100,
speed = sample(3, 100, replace=TRUE),
latitude = seq(from=20, by=0.01, length.out=100),
longitude = seq(from=30, by=0.01, length.out=100))
round_any = function(x, accuracy, f=round){f(x/ accuracy) * accuracy}
library(dplyr)
fakedata %>%
mutate(latitude_round = round_any(latitude, accuracy = 0.1),
longitude_round = round_any(longitude, accuracy = 0.1))
然后使用 dplyr::group_by()
按您的舍入坐标分组,并根据需要汇总时间和速度值。