r-raster

Increment Loop in Batches

…衆ロ難τιáo~ 提交于 2020-01-07 01:49:39
问题 I was hoping someone could help me with a loop function I'm working with. I have tried searching Google and Stack Overflow extensively but, as I don't know the exact search terminology, I fear I am missing some results. With that in mind, I apologise in advance if this question has already been asked but I hope that someone can point me in the right direction for a solution. About My Data I have downloaded 1000s of files from NASAs MODIS satellite. As my study area covers a large area, I've

How to extract all levels from a netcdf file using the raster package?

喜夏-厌秋 提交于 2020-01-06 07:12:58
问题 Related to this question Plotting netcdf file with levels in R But I would like to know how to extract all levels from a netcdf file automatically, without going through one at a time. Do I have to write a custom function or is there a function in raster package that does that? 来源: https://stackoverflow.com/questions/52893780/how-to-extract-all-levels-from-a-netcdf-file-using-the-raster-package

Thornthwaite evapotranspiration on a raster dataset . Error formula not vectorised

浪子不回头ぞ 提交于 2020-01-06 06:00:08
问题 I am trying to calculate evapotranspiration (ET) for running SPEI on a raster dataset by using the Thornthwaite ET formula included in the SPEI package this is my code library(SPEI) library(raster) library(zoo) tm = array(1:(3*4*12*64),c(3,4,12*64)) tm = brick(tm) dates=seq(as.Date("1950-01-01"), as.Date("2013-12-31"), by="month") tm<- setZ(tm,dates) names(tm) <- as.yearmon(getZ(tm)) thornthwaite ET th <- function(Tave, lat) { SPEI::thornthwaite(Tave, lat) } lat <- setValues(a, coordinates(tm

Extract in R fails for small polygons and raster

浪子不回头ぞ 提交于 2020-01-05 04:41:07
问题 This example should be reproducible, the first part (with large polygons) works, the second fails: library(raster) USA.altitude <- getData('alt', country='USA') lower48 <- USA.alt[[1]] Srs1 = Polygons(list(Polygon(cbind(c(-96,-95,-95,-96),c(40,40,41,40)))), "s1") Srs2 = Polygons(list(Polygon(cbind(c(-97,-96,-96,-97),c(40,40,41,40)))), "s2") spdf.large <- SpatialPolygonsDataFrame( SpatialPolygons(list(Srs1,Srs2)), data.frame( z=1:2, row.names=c("s1","s2") ) ) plot(spdf.large) usa.average.elev<

Running raster::stackApply() function in parallel

旧时模样 提交于 2020-01-03 04:45:14
问题 I'm trying to parallelize this example. I have a bunch of rasters that I am trying to aggregate by week of the year. Here is what this looks like in series: # create a raster stack from list of GeoTiffs tifs <- list.files(path = "./inputData/", pattern = "\\.tif$", full.names = TRUE) r <- stack(tifs) # get the date from the names of the layers and extract the week indices <- format(as.Date(names(r), format = "X%Y.%m.%d"), format = "%U") indices <- as.numeric(indices) # calculate weekly means

Confusion about the mask() function in the raster package

筅森魡賤 提交于 2019-12-24 23:53:17
问题 I apologise in advance for the very basic nature of this question, but I'm confused about how the mask() function works in the raster package in R. Reading the documentation for the function it sounds like cells in raster x are set to NA (the default) if these cells match a maskvalue in a mask object (the default maskvalue being NA). However, the description of the mask() function in the book Geocomputation with R by Lovelace et al. (https://geocompr.robinlovelace.net/spatial-operations.html

Error when extracting values from a rasterBrick or rasterStack

谁说胖子不能爱 提交于 2019-12-24 17:12:59
问题 I am having trouble extracting values or a point from a multi band raster of class rasterStack or rasterBrick . 'extract' works well with the individual rasters but posts an error when applied to the rasterStack or brick . > all.var class : RasterBrick dimensions : 89, 180, 16020, 34 (nrow, ncol, ncell, nlayers) resolution : 2, 2 (x, y) extent : -179, 181, -89, 89 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 data source : in memory

Extracting pixels values and coordinates in neighborhood of given buffer in R

这一生的挚爱 提交于 2019-12-24 15:05:04
问题 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 success. library(raster) #create some GeoTIFF rasters r <- raster(ncol=10, nrow=10) s <- stack(lapply(1:8, function(i) setValues(r, runif(ncell(r))))) f1 <- file.path(tempdir(), "sl1.tif") f2 <- file.path(tempdir(), "sl2.tif")

subassignment of selected layers in raster brick

谁都会走 提交于 2019-12-24 09:07:08
问题 I want to modify a subset of layers in a raster brick by multiplying those layers by another raster. For example, if we have a raster brick called 'r.brick' and we try to multiply its layers 2:4 by a raster, 'r.mult', with same row&column dimensions: r.brick[[2:4]] returns layers 2:4, as expected r.brick[[2:4]] * r.mult successfully multiplies those layers, as expected but, if I try to assign the result back into the subset layers I get an error r.brick[[2:4]] = r.brick[[2:4]] * r.mult #

Replace specific value in each band of raster brick in R

白昼怎懂夜的黑 提交于 2019-12-24 08:46:41
问题 I have a multi-band (20 layers) raster loaded into R as a RasterBrick using brick() . My plan is to normalize each band from 0 to 1 using the approach that was proposed in this thread: https://stats.stackexchange.com/questions/70801/how-to-normalize-data-to-0-1-range Here some sample code to visualize my problem: for(j in 1:nlayers(tif)){ min <- cellStats(tif[[j]],'min') max <- cellStats(tif[[j]],'max') for(i in 1:ncell(tif)){ tif[i][j] <- (tif[i][j]-min)/(max-min) } } "tif" contains the