raster

R: Finding the nearest raster cell within a threshold calculated between two rasters

♀尐吖头ヾ 提交于 2020-01-01 23:19:50
问题 I have two perfectly overlapping rasters (same extents and cell size). For every cell in one raster (i.e. for every XY), I would like to determine the Euclidean geographical distance to the closest cell within a given threshold difference between the rasters. Put another way: raster1 and raster2 measure some variable Z. I have a threshold difference for Z values (t) which constitutes a "matching" value (or "close enough") between raster1 and raster2. For each reference cell in raster1, I need

Add text out of levelplot panel area

拈花ヽ惹草 提交于 2020-01-01 11:33:25
问题 I want to add text out of plot area in levelplot. In the following example, I need the text in somewhere in the pointed location. library (raster) library(rasterVis) f <- system.file("external/test.grd", package="raster") r <- raster(f) levelplot(r) I tried mtext function with no success. Any suggestions? mtext("text", side=3, line=0) 回答1: tldr; You can annotate the plot using lower-level grid graphical functions. In this case, do something like: library(grid) seekViewport("plot_01.legend.top

Add text out of levelplot panel area

人走茶凉 提交于 2020-01-01 11:32:47
问题 I want to add text out of plot area in levelplot. In the following example, I need the text in somewhere in the pointed location. library (raster) library(rasterVis) f <- system.file("external/test.grd", package="raster") r <- raster(f) levelplot(r) I tried mtext function with no success. Any suggestions? mtext("text", side=3, line=0) 回答1: tldr; You can annotate the plot using lower-level grid graphical functions. In this case, do something like: library(grid) seekViewport("plot_01.legend.top

R raster recognizing black color raster image

半腔热情 提交于 2019-12-30 11:49:18
问题 The code below produces two boxes on my image. I am planning to analyze pixels within those boxes further. I want to put a condition that if along an edge of a box, there is a black color (or a similar color such as grey) pixel then don't proceed. How can i specify such condition? In below example, in the case of the red square I don't want to proceed further as it has black pixels at the top right hand corner. While I would like to proceed in the case of green square as it doesn't have a

Moving window regression

笑着哭i 提交于 2019-12-30 07:52:29
问题 I want to perform a moving window regression on every pixel of two raster stacks representing Band3 and Band4 of Landsat data. The result should be two additional stacks, one representing the Intercept and the other one representing the slope of the regression. So layer 1 of stack "B3" and stack "B4" result in layer 1 of stack "intercept" and stack "slope". Layer 2 of stack B3 and stack B4 result in layer 2,.... and so on. I already came along the gwr function, but want to stay in the raster

geom_raster interpolation with log scale

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 06:49:51
问题 I'm a bit stuck plotting a raster with a log scale. Consider this plot for example: ggplot(faithfuld, aes(waiting, eruptions)) + geom_raster(aes(fill = density)) But how to use a log scale with this geom? None of the usual methods are very satisfying: ggplot(faithfuld, aes(waiting, log10(eruptions))) + geom_raster(aes(fill = density)) ggplot(faithfuld, aes(waiting, (eruptions))) + geom_raster(aes(fill = density)) + scale_y_log10() and this doesn't work at all: ggplot(faithfuld, aes(waiting,

Can't change raster's extent

流过昼夜 提交于 2019-12-25 14:48:39
问题 I want to crop an elevation raster to add it to a raster stack. It's easy, I did this before smoothly, adding a ecoregions raster to the same stack. But with the elevation one, just doesn't work. Now, there are several questions here in overflow adressing this issue and I tryed a lot of things... First of all, we need this: library(rgdal) library(raster) My stack is predictors2: #Downloading the stack predictors2_full<-getData('worldclim', var='bio', res=10) #Cropping it, I don' need the

R raster rotating images and not changing their size

妖精的绣舞 提交于 2019-12-25 14:12:17
问题 I have below code which rotates an image. But the rotated image has different dimensions. How could we ensure that the rotated images has same dimensions? i.e. if the original image has 50 rows and 30 columns then the rotated image should have 30 rows and 50 columns. library(raster) r1 <- brick("watch1.JPG")#please use any jpg image plotRGB(r1) png("SaveThisPlot.png") plotRGB(t(flip(r1, 2))) dev.off() 回答1: png("SaveThisPlot.png",width=nrow(r1),height=ncol(r1)) 来源: https://stackoverflow.com

R raster rotating images and not changing their size

不羁岁月 提交于 2019-12-25 14:12:05
问题 I have below code which rotates an image. But the rotated image has different dimensions. How could we ensure that the rotated images has same dimensions? i.e. if the original image has 50 rows and 30 columns then the rotated image should have 30 rows and 50 columns. library(raster) r1 <- brick("watch1.JPG")#please use any jpg image plotRGB(r1) png("SaveThisPlot.png") plotRGB(t(flip(r1, 2))) dev.off() 回答1: png("SaveThisPlot.png",width=nrow(r1),height=ncol(r1)) 来源: https://stackoverflow.com

h5py: chunking on resizable dataset

雨燕双飞 提交于 2019-12-25 09:00:09
问题 I have a series of raster datasets which I want to combine into a single HDF5 file. Each raster file will be converted into an array with the dimensions 3600 x 7000 . As I have a total of 659 files, the final array would have a shape of 3600 x 7000 x 659 , too big for my (huge) amount of RAM. I'm fairly new to python and HDF5 itself, but basically my approach is to create a dataset with the required 2-d dimensions and then iteratively read the files into arrays and append to the dataset. I'm