raster

ClusterR with multiple raster stacks

淺唱寂寞╮ 提交于 2019-12-10 19:25:52
问题 Here is an example that raster library provides for using clusterR and overlay functions: library(raster) beginCluster() r <- raster() r[] <- 1:ncell(r) s <- stack(r, r*2, r*3) f2 <- function(d,e,f) (d + e) / (f * param) param <- 122 ov <- clusterR(s, overlay, args=list(fun=f2), export='param') I want to know how to run that function if I have multiple raster stacks: s <- stack(r, r*2, r*3) s2 <- stack(r*2, r*3, r*4) s3 <- stack(r*3, r*4, r*5) I want something like this ( d,e,f in function f2

repeat same raster layer to create a raster stack

妖精的绣舞 提交于 2019-12-10 18:20:11
问题 I am trying to create a raster stack from a rasterlayer, where the raster stack is just the same raster layer repeated a certain number of times. I can do something like this: library(raster) rasterstack <- addLayer(rasterlayer, rasterLayer, rasterLayer) and this works. However, i want the stack to be about a 1000 layers. I guess i could just loop through, but i was wondering if there was a more sophisticated way to doing this. The reason I am trying to do this is to calculate the weighted

R raster plotting an image, draw a circle and mask pixels outside circle

我的未来我决定 提交于 2019-12-10 15:05:00
问题 Code below plots an image and then plots circle on that image. I want to make all pixels that fall outside that circle black. How could I do that? library(raster) library(plotrix) r1 <- brick(system.file("external/rlogo.grd", package="raster")) width=50 height=40 x <- crop(r1, extent(0,width,0,height)) plotRGB(x) circlex=20 circley=15 radius=10 draw.circle(circlex,circley,radius,border="blue") 回答1: Look at the 'x'-object with str() and you see this: ..@ data :Formal class '.MultipleRasterData

Extracting pixels values and coordinates in neighborhood of given buffer with NA values

醉酒当歌 提交于 2019-12-10 12:16:45
问题 I want to get values (pixels values), coordinates (x and y) and attribute ( status ) in the neighborhood (for example in a buffer=6 meters) of random coordinates ( pts ), using extract function in raster package. I try to organize the results in data.frame without NA values and this problem is solved by @Robert Hijmans in Extracting pixels values and coordinates in neighborhood of given buffer in R. But, if I have some coordinates outside of one of raster (and I create the s2 raster with this

Read Netcdf sub categories and convert to grid

僤鯓⒐⒋嵵緔 提交于 2019-12-10 11:38:35
问题 I also posted this question on stack gis 1. From the netcdf4 data that have sub categories, I want to be able to read "Retrieval/fs" variable. I also want to read them and convert to raster girds, but it seems that raster doesn't support netcdf4. I appreciate any suggestions. library(ncdf4) library(raster) file <- "http://140906_B7101Ar_150909171225s.nc4" names(file$var) "latitude" ... "longitude"... "Retrieval/fs" lat <- raster(file, varname="latitude") lon <- raster(file, varname="longitude

Bring rasters to same extent by filling with NA - in R

╄→尐↘猪︶ㄣ 提交于 2019-12-10 10:28:28
问题 I have several cropped rasters with different geometry/outlines. Specifically spatial yield maps from several years of the same field, but the extent varies - the measurements were not always overall the whole field, but in some years only part of it. I want to calculate a mean value of those maps and combine them into one mean-value-raster. That does mean however, that not for every pixel in let's say 5 layers/rasters there is a value. I could accept these missing values to be NA, so the

How to legend a raster using directly the raster attribute table and displaying the legend only for class displayed in the raster?

孤街浪徒 提交于 2019-12-10 05:48:02
问题 I would like to use the raster attribute table information to create the legend of a raster such as the raster 1 and display the legend only for the class displayed in the raster. I build an example to explain what I would like to get. 1/ Build the raster r <- raster(ncol=10, nrow=10) values(r) <-sample(1:3,ncell(r),replace=T) 2/ Add the Raster Attribute Table r <- ratify(r) # build the Raster Attibute table rat <- levels(r)[[1]]#get the values of the unique cell frot the attribute table rat

R - Chaging specific cell values in a large raster layer

你。 提交于 2019-12-09 23:29:20
问题 I am working with R "raster" package and have a large raster layer (62460098 cells, 12 Mb for the object). My cell values range from -1 to 1. I have to replace all negative values with a 0 (example: a cell that has -1 as value has to become a 0). I tried to do this: raster[raster < 0] <- 0 But it keeps overloading my RAM because of the raster size. OS: Windows 7 64-bits RAM size: 8GB Tks! 回答1: You can do r <- reclassify(raster, c(-Inf, 0, 0)) This will work on rasters of any size (no memory

Reading an ASC file into R

非 Y 不嫁゛ 提交于 2019-12-09 14:14:24
问题 I'm currently trying to extract information from various "ASC" files into R in order to perform analysis on the data. The issue is that I am unsure of how exactly to read in the files. I attempted a standard read.table functions, but all the numbers were exactly the same (-9999.00). In order to rule out the possibility of data corruption, I read in another ASC file and got the same results. The only thing I know for certain, is that the file size between them is exactly the same. Is there

plot raster factor values with ggplot

可紊 提交于 2019-12-09 13:48:16
问题 I have problems plotting a raster with factor values using ggplot2. library(ggplot2) library(raster) first, load raster data f <- system.file("external/test.grd", package="raster") r <- raster(f) extract coordinates and values val <- getValues(r) xy <- as.data.frame(xyFromCell(r,1:ncell(r))) xy <- cbind(xy,val) plot the grid using geom_raster(). Everything works fine. ggplot(xy, aes(x=x, y=y, fill=val)) + geom_raster() + coord_equal() I don not have a continuous raster, but a classified.