raster

Java getSubimage() outside of raster

耗尽温柔 提交于 2019-11-27 08:08:15
问题 I'm trying to take an image and store it in an array of 16x16 subimages. The image I am using is 512x512 pixels. However, while iterating through the loop, getSubimage() is stopped by a Raster exception. Here is the code: public class TileList extends JPanel { private static final int width = 16; //width of a tile private static final int height = width; private int col = 1; private int row = 1; private BufferedImage image; File tilesetImage = new File("image.png"); BufferedImage tileset[];

How to extract values from rasterstack with xy coordinates?

做~自己de王妃 提交于 2019-11-27 04:35:38
问题 I have a rasterstack (5 raster layers) that actually is a time series raster. r <- raster(nrow=20, ncol=200) s <- stack( sapply(1:5, function(i) setValues(r, rnorm(ncell(r), i, 3) )) ) s class : RasterStack dimensions : 20, 200, 4000, 5 (nrow, ncol, ncell, nlayers) resolution : 1.8, 9 (x, y) extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 names : layer.1, layer.2, layer.3, layer.4, layer.5 min values : -9.012146, -9

How to rotate an image R raster

蓝咒 提交于 2019-11-27 03:00:16
问题 I have code below which saves an image to my pc. I would like to rotate that image by 45,90 and 135 degrees around its center (or bottom left hand corner) and then save as 3 different images. How could I do that? library(raster) r1 <- brick(system.file("external/rlogo.grd", package="raster")) x <- crop(r1, extent(0,50,0,50)) plotRGB(x) png(width=50, height=50) par(mai=c(0,0,0,0)) image(x) dev.off() ---------update1------------------------- Based upon the accepted answer the working code is as

How to create a raster from a data frame in r?

坚强是说给别人听的谎言 提交于 2019-11-27 01:53:34
问题 I have a data frame in which values (l) are specified for Cartesian coordinates (x, y) as in the following minimal working example. set.seed(2013) df <- data.frame( x = rep( 0:1, each=2 ), y = rep( 0:1, 2), l = rnorm( 4 )) df # x y l # 1 0 0 -0.09202453 # 2 0 1 0.78901912 # 3 1 0 -0.66744232 # 4 1 1 1.36061149 I want to create a raster using the raster package, but my reading of the documentation has not revealed a simple method for loading data in the form that I have it into the raster

extract RGB channels from a jpeg image in R

扶醉桌前 提交于 2019-11-26 19:46:46
问题 In order to classify a jpeg image in R, I would like to get the RGB values of each pixel. My question: Is there a way to extract RGB channels from a jpeg image in R ? 回答1: You have several package to read in JPEG. Here I use package jpeg : library(jpeg) img <- readJPEG("Rlogo.jpg") dim(img) [1] 76 100 3 As you can see, there is 3 layers: they correspond to your R, G and B values. In each layer, each cell is a pixel. img[35:39,50:54,] , , 1 [,1] [,2] [,3] [,4] [,5] [1,] 0.5098039 0.5921569 0

Legend of a raster map with categorical data

十年热恋 提交于 2019-11-26 18:17:16
问题 I would like to plot a raster containing 4 different values (1) with a categorical text legend describing the categories such as 2 but with colour boxes: I've tried using legend such as : legend( 1,-20,legend = c("land","ocean/lake", "rivers","water bodies")) but I don't know how to associate one value to the displayed color. Is there a way to retrieve the colour displayed with 'plot' and to use it in the legend? 回答1: The rasterVis package includes a Raster method for levelplot() , which