Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 8993

Raster is a data format consisting of regular grids of values, usually stored in an image-like format.

0 votes
Accepted

histogram of raster coordinates in R

The histograms are different. head(table(one)) ##one ##31 32 33 34 35 36 ## 1 2 1 2 2 2 head(table(two)) ##two ##18 19 22 23 24 25 ## 2 1 3 4 2 5 stem(one, 0.5) # The decimal point …
Robert Hijmans's user avatar
5 votes
Accepted

Identifying value of closest non-NA pixel

You can do something along these lines: Example data: library(raster) r <- raster(ncol=10,nrow=10, ext=extent(c(0,10,0,10)), crs='+proj=utm +zone=1') r[] <- 1 r[15:42] <- 2 set.seed(0) r[sample(ncell …
Robert Hijmans's user avatar
1 vote

Error during DEM interpolation for raster grid : data item in gstat object and newdata have ...

The general approach you are taking works for me with terra and with raster. … dem_rast <- raster(floor(extent(dem_points_clip)), res=5) …
Robert Hijmans's user avatar
3 votes

Detect whether there is a spatial polygon in a spatial extent

'sp' is a Spatial* object library(raster) e <- extent(c(0,10,0,10)) intersect(e, extent(sp)) But it may indeed be, as whuber points out, that the polygon is in fact not inside extent e. …
Robert Hijmans's user avatar
7 votes
Accepted

How do I get rid of edge effects while using focal in R to smooth a raster?

Also, as you want to fill in missing values, not change existing values, I would use NAonly = TRUE, together with pad=TRUE (to pad virtual rows and columns with NAs outside of the raster). … Here is an example: library(raster) # example data logo <- raster(system.file("external/rlogo.grd", package="raster")) set.seed(0) i <- sample(ncell(logo), 200) logo[i] <- NA plot(logo) m <- matrix …
Robert Hijmans's user avatar
3 votes

Random sampling of raster using R?

You can use the sampleRandom function: library(raster) r <- raster(ncol=30,nrow=20) r[] <- 1:ncell(r) x <- sampleRandom(r, ncell(r)*.3, asRaster=TRUE) …
Robert Hijmans's user avatar
1 vote

Multiply raster brick by vector based on codition from another vector in R

Here are three alternative approaches to terra::app that Jeffrey Evans proposed; instead using ifel, selectRange and lapp. I am not saying these are better in any way, but they may be easier to use. J …
Robert Hijmans's user avatar
2 votes

How to store raster brick in memory, rather than on disk in R?

To load all values in RasterBrick into RAM you can use readAll library(raster) b <-brick("tmmn_2020.nc") x <- readAll(b) But this will not help you if you cannot have that much data in RAM, as you say …
Robert Hijmans's user avatar
1 vote
Accepted

Why Stacking rasters return all values as NAs?

The NA's here refer to the fact that the min and max value are unknown (this is no longer the case in the current version of 'raster'). …
Robert Hijmans's user avatar
1 vote

regression model with randomForest in raster package

Impossible to know from your description. But you can try things like the below to see what is going on: # get values of a few cells cells <- 100000:100010 x <- data.frame(w1[cells]) x predict(s2.rf …
Robert Hijmans's user avatar
1 vote
Accepted

How to compute climatology of 3 days moving averages for rasters pixel by pixel?

x <- calc(st1, function(x) movingFun(x, 3, mean)) y <- st1 - x
Robert Hijmans's user avatar
4 votes
Accepted

Applying different equation based on conditional statement for raster value in R?

<- function(x,y) { z <- rep(NA, length(x)) i <- which(y == 1) z[i] <- x[i] * 3 i <- which(y == 2) z[i] <- x[i] * 33 i <- which(y == 3) z[i] <- x[i] * 333 z } library(raster … ) r1 <- r2 <- raster(nrow=5, ncol=5) r1[] <- runif(ncell(r1)) * 10 r2[] <- round(runif(ncell(r2),1,3)) x <- overlay(r1, r2, fun=f) …
Robert Hijmans's user avatar
1 vote

Rasterize gives weird image

What you are seeing is a map of one raster cell (~ 9.5 - 10.5; 46.3 - 47.3) that has a single value (36). Had you provided more information, e.g. show(rMerge), it would have been very easy to spot. … Or use the raster(u, nrow=10, ncol=10) u <- union(union(extent(ro),extent(ra)),extent(co)) rast <- raster(u, ncol=10, nrow=10) r1 <- rasterize(ro, rast) r2 <- rasterize(ra, rast) r3 <- rasterize(co, rast …
Robert Hijmans's user avatar
1 vote

Include non-raster object in overlay function in R

whuber showed the way, but here's another way to get there (using the functions that match the operations he suggests) d <- c(.25,.50,.75) m <- cbind(1:3, d) r3 <- reclassify(r2, m) out <- r1 * r3
Robert Hijmans's user avatar
3 votes
Accepted

Extracting point data for each lat and long from raster file into a dataframe

If so, yo can do the following # Your code (simplified) library(raster) files= list.files(pattern='\\.grd$', full.names=TRUE) s <- stack(files) pt<- read.csv("latandlong") point <- SpatialPoints(pt) df …
Robert Hijmans's user avatar

1
2 3 4 5
14
15 30 50 per page