raster

How can I find the pixel-wise standard deviation?

江枫思渺然 提交于 2019-11-30 18:33:41
问题 I have 20 rasters with same resolution and extent. It's a time series and each raster is for one year. And I want to calculate the pixel-wise standard deviation of all rasters.So far, I am using the raster package. qq2<-list(maxras1,maxras2,maxras3,maxras4,maxras5,maxras6,maxras7,maxras8,maxras9,maxras10) qq2stack<-stack(qq2) qq2mean<-mean(qq2stack) qq2sd<-sd(qq2stack) The mean works. But standard deviation is giving me this error: Error in as.double(x) : cannot coerce type 'S4' to vector of

How to interpolate between rasters?

房东的猫 提交于 2019-11-30 16:10:13
If have three rasters(as matrix): r1 <- raster(nrows=10, ncols=10); r1 <- setValues(r1, 1:ncell(r1)) r16 <- raster(nrows=10, ncols=10);r16 <- setValues(r16, 1:ncell(r16)) r30 <- raster(nrows=10, ncols=10);r30 <- setValues(r30, 1:ncell(r30)) I would like to linearly interpolate r1,c16,c30 to find the values in between i.e. r2,r3,r4,......r15 then r17,r18,r19,..........r29 . Is this possible using R? Robert Hijmans Here is a way to do that library(raster) r <- raster(nrows=10, ncols=10); values(r) <- NA x <- sapply(1:30, function(...) r) x[[1]] <- setValues(r, runif(ncell(r))) x[[16]] <-

How to change the resolution of a raster layer in R

扶醉桌前 提交于 2019-11-30 13:57:50
问题 I have several high resolution raster layers in R that I am working with. The level of detail is excessive for some of the analyses I am running, so I would like to speed things up by reducing the resolution. The coordinate system is UTM so the units are meters. The resolution says it is 30, 30 (x, y). So it seems that the resolution here is 30m. Could someone please advise me on how to change the resolution to 120m instead? I have read the help for the resample() and projectRaster()

R crop raster data and set axis limits

此生再无相见时 提交于 2019-11-30 11:40:22
问题 With your help in another thread I have managed to plot some global maps. First I convert meteorological GRIB2 data to Netcdf and then plot the global maps. Now I want to plot just a subregion of the map. I have tried crop command and succesfully extracted the subregion of the global nc file. But when plotting I can't find how to control axis limits. It plots a map bigger than data region so big white spaces appear on both sides. This is the script I'm using to plot maps library("ncdf")

R plot background map from Geotiff with ggplot2

狂风中的少年 提交于 2019-11-30 10:37:43
With the R base plot, I can plot any geotiff with the following command: library("raster") plot(raster("geo.tiff")) For example, downloading this data, I would do the follwing: setwd("C:/download") # same folder as the ZIP-File map <- raster("smr25musterdaten/SMR_25/SMR_25KOMB_508dpi_LZW/SMR25_LV03_KOMB_Mosaic.tif") How do you Plot GeoTif Files in ggplot2? EDIT: 1: I've replaced the greyscale map from the sample files with a coloured map to ilustrate the problem of the missing colortable. 2: With the help of Pascals answer, I was able to adapt and improve this solution and make it more dynamic

convert matrix to raster in R

杀马特。学长 韩版系。学妹 提交于 2019-11-30 09:39:45
I have a matrix data with spatial coordinates and one variable. The spatial resolution is 1000 meters. > str(dat1) > List of 3 > $ x: num [1:710] 302340 303340 304340 305340 306340 ... > $ y: num [1:1241] 5431470 5432470 5433470 5434470 5435470 ... > $ z: num [1:710, 1:1241] 225 225 225 225 225 ... I want to convert it into raster format. > dat1$x[1:10] > [1] 302339.6 303339.6 304339.6 305339.6 306339.6 307339.6 308339.6 309339.6 310339.6 311339.6 > dat1$y[1:10] > [1] 5431470 5432470 5433470 5434470 5435470 5436470 5437470 5438470 5439470 5440470 I used the following code to do it. But the

Is StretchBlt HALFTONE == BILINEAR for all scaling?

不想你离开。 提交于 2019-11-30 05:39:44
问题 Can anyone clarify if the GDI StretchBlt function for the workstation Win32 API performs bilinear interpolation for scaling to both larger and smaller images for 24/32-bit color images? And if not, is there a GDI ( not GDI+) function that does this? The SetStretchBltMode fn has a setting HALFTONE which is documented as follows: HALFTONE Maps pixels from the source rectangle into blocks of pixels in the destination rectangle. The average color over the destination block of pixels approximates

raster package taking all hard drive

雨燕双飞 提交于 2019-11-30 05:19:59
I am processing a time series of rasters (modis ndvi imagery) to calculate average and st.deviation of the series. Each yearly series is composed of 23 ndvi.tif images, each of 508Mb, so total is a big 11Gb to process. Below is the script for one year. I have to repeat this for a number of years. library(raster) library("rgeos") filesndvi <- list.files(, pattern="NDVI.tif",full.names=TRUE) filesetndvi10 <- stack(filesndvi) names(filesetndvi10) avgndvi10<-mean(filesetndvi10) desviondvi10 <- filesetndvi10 - avgndvi10 sumdesvioc <-sum(desviondvi10^2) varndvi10 <- sumdesvioc/nlayers(filesetndvi10)

Plotting a raster with the color ramp diverging around zero

一笑奈何 提交于 2019-11-30 04:17:40
I am trying to plot a map with positive and negative values. All positive values should have red color while negative should have blue color and zero should have white just like in this sample plot with discrete colors Below is the code I'm using: library (rasterVis) ras1 <- raster(nrow=10,ncol=10) set.seed(1) ras1[] <- rchisq(df=10,n=10*10) ras2=ras1*(-1)/2 s <- stack(ras1,ras2) levelplot(s,par.settings=RdBuTheme()) Thanks very much for providing a general solution which can be applied in other mapping exercises as well. jbaums I wrote a gist to do this. It takes a trellis object generated by

Plot continuous raster data in binned classes with ggplot2 in R

落花浮王杯 提交于 2019-11-30 04:14:13
问题 I quite like the look and feel of ggplot2 and use them often to display raster data (e.g facetting over timesteps for time-varying precipitation fields is very useful). However, I'm still wondering whether it is easily possible to bin the continuous raster values into discrete bins and assign to each bin a single colour , that is shown in the legend (as many GIS systems do). I tried with the guide = "legend" , and breaks arguments of the scale_fill_gradient option. However these affect just