raster

Convert raster into matrix with R

丶灬走出姿态 提交于 2021-01-27 04:40:46
问题 I'm currently convert original matrix into a raster to use the focal function, then I would like to convert back the raster into matrix. But I have an error message when I try to use the raster function as.matrix(). Even with this very simple example: r <- raster(ncol=3, nrow=3) r[] <- 1:ncell(r) as.matrix(r) Here is what I got: Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), : length of 'dimnames' [1] not equal to array extent I'm using RSTUDIO, R version 3.4.0 and

Convert raster byte[] image data to column Format in C#

折月煮酒 提交于 2020-07-14 06:48:48
问题 I'm trying to convert a byte array from an image that is in Raster format, which reads from left to right, to Column format, which reads from top to bottom. The problem looks simple, we have two-dimensional array of bits (width/height of image). In Raster format, you read the bits from left to right, in Column format you read the bits from top to bottom. I try to do this to support Column format printing of the ESC/POS protocol. I already have the image in Raster format, now I'm trying to

How can I calculate the sd? Error in as.double(x): cannot coerce type 'S4' to vector of type 'double'

ぃ、小莉子 提交于 2020-06-16 06:39:13
问题 Do somebody know what is wrong with my code? I edited the post, because i didn´t give you the data. I want to calculate the sd. The calculation of the mean worked. Here is the link to the cropped data: https://drive.google.com/drive/folders/1ljT1fzaDlSmn_3j7zHshS5lrV1wBvVQD library(raster) r <- brick("filename") #mean mean <- mean(r) #sd standard_dev <- sd(r) standard_dev2 <- sd(r, na.rm =TRUE) standard_deviation <- calc(r, sd) 回答1: You want the compute the sd for each cell in a RasterBrick.

Controlling legend and colors for raster values in R?

只愿长相守 提交于 2020-05-26 09:39:04
问题 I'm trying to plot an ESRI Grid as a raster image of a surface. I've figured out how to make the plot, but not how to control R's color scale. # open necessary libraries library("raster") library("rgdal") library("ncdf") # goal: select an ESRI Grid ASCII file and plot it as an image. infile <- file.choose("Results") r <- raster(infile) # read in metadata from ESRI output file, split up into relevant variables info <- read.table(infile, nrows=6) NCOLS <- info[1,2] NROWS <- info[2,2] XLLCORNER