Last active
October 10, 2022 03:10
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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