我有数千个点数据坐标(以下代码中的示例),这些坐标是从拖拉机制导系统导出的,每个坐标带有时间戳。我创建了一个1 m分辨率的空栅格。如何计算每个栅格像元在指定距离(例如14米)内的点数,而仅计算点的不在点的时间戳(±3)范围内的点数?
libs <- c("raster","dplyr", "rgdal", "sp", "sf")
have <- libs %in% rownames(installed.packages())
if(any(!have)) install.packages(libs[!have])
sapply(libs, function(i) require(i, character.only=TRUE))
pts70 <- structure(list(Latitude = c(35.09263063, 35.09263784, 35.09264402,
35.09265182, 35.09265815, 35.09266566, 35.09267184, 35.09267979,
35.09269097, 35.09269627, 35.09270054, 35.09270422, 35.09271511,
35.09272232, 35.09272997, 35.09273821, 35.09273468, 35.09274645,
35.09277486, 35.09280812, 35.09284226, 35.09287464, 35.09290098,
35.0929129, 35.09291143, 35.09289568, 35.09287273, 35.09285683,
35.09285477, 35.09287331, 35.09290672, 35.09294866, 35.09298825,
35.09301548, 35.09301769, 35.09301077, 35.09299223, 35.09296839,
35.09294557, 35.09292924, 35.09291894, 35.09290893, 35.09289936,
35.09289112, 35.09288273, 35.0928742, 35.09286654, 35.09285771,
35.09285168, 35.09284314, 35.09283593, 35.0928271, 35.09282092,
35.09281209, 35.09280444, 35.09279826, 35.09278899, 35.09278148,
35.0927728, 35.09276544, 35.09275764, 35.09275146, 35.09274219,
35.0927363, 35.09272747, 35.09271967, 35.09271069, 35.09270378,
35.0926948, 35.09268847, 35.09268038), Longitude = c(-93.98941262,
-93.98937898, -93.98934607, -93.98931225, -93.9892779, -93.98924354,
-93.98921387, -93.98918347, -93.9891466, -93.98910901, -93.98907951,
-93.98904479, -93.98900594, -93.98897033, -93.98893741, -93.9889027,
-93.98885612, -93.98880917, -93.98880414, -93.98880971, -93.98880432,
-93.98878651, -93.98875773, -93.9887214, -93.98868668, -93.98865611,
-93.98862265, -93.98858002, -93.98853092, -93.98848326, -93.98845088,
-93.98844207, -93.98845808, -93.98849369, -93.9885329, -93.98856977,
-93.98859603, -93.98861744, -93.98864136, -93.9886714, -93.98870395,
-93.98873669, -93.98876906, -93.98880216, -93.98883651, -93.98887015,
-93.98890414, -93.98893849, -93.98897069, -93.98900486, -93.98903922,
-93.98907357, -93.98910811, -93.98913958, -93.98917268, -93.98920577,
-93.98923941, -93.98927196, -93.98930524, -93.98933833, -93.98937215,
-93.98940344, -93.98943744, -93.98947125, -93.98950453, -93.98953834,
-93.9895718, -93.98960579, -93.98963889, -93.98967288, -93.98970669
), Timestamp = c(1540321036L,
1540321037L, 1540321038L, 1540321039L, 1540321040L, 1540321041L,
1540321042L, 1540321043L, 1540321044L, 1540321045L, 1540321046L,
1540321047L, 1540321049L, 1540321050L, 1540321051L, 1540321052L,
1540321053L, 1540321054L, 1540321055L, 1540321056L, 1540321057L,
1540321058L, 1540321059L, 1540321060L, 1540321061L, 1540321062L,
1540321063L, 1540321064L, 1540321065L, 1540321066L, 1540321067L,
1540321068L, 1540321069L, 1540321070L, 1540321071L, 1540321072L,
1540321073L, 1540321074L, 1540321075L, 1540321076L, 1540321077L,
1540321078L, 1540321079L, 1540321080L, 1540321081L, 1540321082L,
1540321083L, 1540321084L, 1540321085L, 1540321086L, 1540321087L,
1540321088L, 1540321089L, 1540321090L, 1540321091L, 1540321092L,
1540321093L, 1540321094L, 1540321095L, 1540321096L, 1540321097L,
1540321098L, 1540321099L, 1540321100L, 1540321101L, 1540321102L,
1540321103L, 1540321104L, 1540321105L, 1540321106L, 1540321107L
)), row.names = 3371:3441, class = "data.frame")
sf_pts <- pts70 %>%
sf::st_as_sf(coords = c("Longitude", "Latitude"), agr="constant") %>%
sf::st_set_crs(4326) %>%
sf::st_transform(crs = 32615)
r <- raster()
bb <- extent(sf_pts)
r <- setExtent(r, bb)
res(r) <- 1
crs(r) <- '+init=EPSG:32615'