r-raster

projectRaster consuming too much memory

强颜欢笑 提交于 2021-01-27 13:20:56
问题 I'm doing some spatial stuff in R and out of the blue some of my code will no longer work on a computer that I've been using for years, specifically because it's "running out of memory." ## Raster going in xx <- raster(fatNames[[i]]) xx class : RasterLayer dimensions : 5160, 14436, 74489760 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -172.3, -52, 23.5, 66.5 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 data

Convert raster into matrix with R

丶灬走出姿态 提交于 2021-01-27 04:40:46
问题 I'm currently convert original matrix into a raster to use the focal function, then I would like to convert back the raster into matrix. But I have an error message when I try to use the raster function as.matrix(). Even with this very simple example: r <- raster(ncol=3, nrow=3) r[] <- 1:ncell(r) as.matrix(r) Here is what I got: Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), : length of 'dimnames' [1] not equal to array extent I'm using RSTUDIO, R version 3.4.0 and

Count of sampling points within a grid cell

感情迁移 提交于 2021-01-24 11:33:35
问题 Calculate the total number of sampling points within each grid cell of a spatial grid. I would like to make a grid and calculate the total count of sampling points within each grid cell. I created a randomly generated data and grid, and tried to calculate the number of records within a grid cells using both the sf and raster packages, using previous similar SO questions, but wthout success. I have also looked into the extract function. Im fairly new to spatial analysis. library(sf) library

calculate and plot vector field of an arbitrary rasterLayer

我只是一个虾纸丫 提交于 2021-01-21 04:15:46
问题 Problem statement: With ggquiver::geom_quiver() we can plot vector fields, provided we know x , y , xend , and yend . How can I calculate these parameters for an arbitrary RasterLayer of elevations? How can I ensure that the size of these arrows indicates the slope for that particular vector such that the arrows appear different lengths proportional to the gradient at that location (e.g., the first plot below)? Background: # ggquiver example library(tidyverse) library(ggquiver) expand.grid(x

calculate and plot vector field of an arbitrary rasterLayer

試著忘記壹切 提交于 2021-01-21 04:15:06
问题 Problem statement: With ggquiver::geom_quiver() we can plot vector fields, provided we know x , y , xend , and yend . How can I calculate these parameters for an arbitrary RasterLayer of elevations? How can I ensure that the size of these arrows indicates the slope for that particular vector such that the arrows appear different lengths proportional to the gradient at that location (e.g., the first plot below)? Background: # ggquiver example library(tidyverse) library(ggquiver) expand.grid(x

calculate and plot vector field of an arbitrary rasterLayer

血红的双手。 提交于 2021-01-21 04:13:53
问题 Problem statement: With ggquiver::geom_quiver() we can plot vector fields, provided we know x , y , xend , and yend . How can I calculate these parameters for an arbitrary RasterLayer of elevations? How can I ensure that the size of these arrows indicates the slope for that particular vector such that the arrows appear different lengths proportional to the gradient at that location (e.g., the first plot below)? Background: # ggquiver example library(tidyverse) library(ggquiver) expand.grid(x

If raster value NA search and extract the nearest non-NA pixel

我是研究僧i 提交于 2020-12-01 10:09:54
问题 On extracting values of a raster to points I find that I have several NA 's, and rather than use a buffer and fun arguments of extract function, instead I'd like to extract the nearest non- NA Pixel to a point that overlaps NA . I am using the basic extract function: data.extr<-extract(loc.thr, data[,11:10]) 回答1: Here's a solution without using the buffer. However, it calculates a distance map separately for each point in your dataset, so it might be ineffective if your dataset is large. set

If raster value NA search and extract the nearest non-NA pixel

爱⌒轻易说出口 提交于 2020-12-01 10:08:35
问题 On extracting values of a raster to points I find that I have several NA 's, and rather than use a buffer and fun arguments of extract function, instead I'd like to extract the nearest non- NA Pixel to a point that overlaps NA . I am using the basic extract function: data.extr<-extract(loc.thr, data[,11:10]) 回答1: Here's a solution without using the buffer. However, it calculates a distance map separately for each point in your dataset, so it might be ineffective if your dataset is large. set