Created
April 4, 2017 13:39
-
-
Save noamross/c173748aec0e77ef13d351a181b47a14 to your computer and use it in GitHub Desktop.
Non-functional extract of fasterraster usage
This file contains hidden or 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
bias_matrix <- as.matrix(bias_raster) # Bias measure | |
num_matrix <- as.matrix(number_raster) # Number of samples measure | |
# Boolean matrix for signficant bias | |
bias_mat2 <- ifelse((bias_matrix > bias_funs$upper(num_matrix)) | bias_matrix < bias_funs$lower(num_matrix), 1, NA) | |
# Convert bias boolean to shapes. This is a list of shapes, each shape being an NX2 matrix of points. | |
bias_shapes <- fasteraster::raster2vector(bias_mat2) %>% | |
# Remove shapes that are actually just points or lines (<= 3 defining points) | |
{Filter(function(x) nrow(x) > 3, .) } %>% | |
# Convert matrix coords to lat/long for each shape | |
lapply(function(x) cbind(360*x[,2]/ncol(bias_matrix) - 180, -180*x[,1]/nrow(bias_matrix) + 90)) | |
# Convert the list of shapes into a Spatial object | |
z <- seq_along(bias_shapes) | |
bias_p <- SpatialPolygons(lapply(z, function(z) Polygons(list(Polygon(bias_shapes[[z]])), z)), proj4string = CRS(proj4string(bias_raster))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment