Skip to content

Instantly share code, notes, and snippets.

@chapmanjacobd
Last active October 10, 2022 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chapmanjacobd/fba001fc5c45874455f28db0fbebe2e2 to your computer and use it in GitHub Desktop.
Save chapmanjacobd/fba001fc5c45874455f28db0fbebe2e2 to your computer and use it in GitHub Desktop.
remove XY points to find which points provide the most coverage without moving cluster location (2D LIDAR)
require(raster)
require(sf)
require(dplyr)
require(data.table)
shiftReduceRaster = function (x, y) {
r <- raster::shift(r, x*xres(r), y*yres(r))
# get cell numbers
cells <- cellFromXY(r, pts)
# pick one point per cell
sel <- aggregate(pts, list(cells), function(i)i[1])
assign("pts", sel[,c("X", "Y",'id')], envir = .GlobalEnv)
}
sort_abs = function(x, na.last = TRUE, decreasing = FALSE) {
x[order(abs(x), na.last = na.last, decreasing = decreasing)]
}
shiftIntervals = sort_abs(seq(from = -1, to = 1, by = 0.05)) # start with 0,0
pts <- fread(file = '~/test.csv',na.strings = '')[,c("X", "Y",'id')]
r <- raster(ncol=36000, nrow=18000, vals=1) # takes 8GB of RAM
for (x in shiftIntervals) {
for (y in shiftIntervals) {
shiftReduceRaster(x, y)
}
gc()
}
rm(r)
gc()
fwrite(pts, file = '~/output.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment