Search Results
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 |
Raster is a data format consisting of regular grids of values, usually stored in an image-like format.
3
votes
Accepted
Find which latitude and longitude values are falling in which raster cells
First, give each raster cell a unique value when you create the raster. I'd also recommend giving the raster the extent of your coordinates. … So:
metersCoordinates <- totalMeterDatabase[,c("longitude","latitude")]
coordinates(metersCoordinates) <- ~longitude+latitude
r <- raster(matrix(seq(1,6000*2000), ncol=6000, nrow=2000),
xmx …
2
votes
Reclassifying raster stack based on condition and other layers using R?
The bracket extract operators work on rasters in R. So you dont need to use setValues or overlay. I would do this:
r1[r1 > r2] <- 1
r1[r1 < r3] <- 0
r1[!(r1 > r2 | r1 < r3)] <- r4[!(r1 > r2 | r1 < …
8
votes
5
answers
9k
views
In R, set NA cells in one raster where another raster has values
I want to set values to NA in the first raster where the second raster has values. … I think this should be simple, using the raster package, with two RasterLayer objects raster1 and raster2, both the same extent and snapped to each other. They are 29775x29930. …
1
vote
0
answers
646
views
Subset moving window when using focal on raster in R
I've tried two ways to do this:
One is to pass multiple filters over the same raster, and then combine their outputs. … I tried this and it takes an incredibly long time, so I think it would be more efficient to pass one 7x7 filter over the raster, and have a conditional function that subsets the window to 5x5 or 3x3 based …
6
votes
3
answers
26k
views
Unable to read raster into R: 'TIFFReadDirectory:Failed to read directory at offset'
I'm getting a weird error when trying to read a raster into R. … >r <- raster('myraster.tif')
Error in .local(.Object, ...) :
TIFFReadDirectory:Failed to read directory at offset 2606110
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", …
1
vote
Improves performance on R working with raster files
To assign raster values to 0, you can do something like this:
r <- raster('yourraster.tif')
r[is.na(r)] <- 0 #Convert all NAs within extent of r to 0
r[r < 0] <- 0 #Convert all negative numbers … So:
for (i in 1:length(all.files)){
r1<-raster(all.files[i])
re1<-crop(r1,e)
re1<-re1/10000
re1[is.na(re1)] <- 0
re1[re1 < 0] <- 0
writeRaster(re1,filename=paste(substr(all.files[i],80,86 …
3
votes
2
answers
3k
views
Display two-dimensional color gradient for two different quantities
I have two overlapping raster layers. One contains quantity A from 0 to 100, and the other contains quantity B from 0 to 100. …