raster

How to create Image From Array of Pixel Values and known width and height..?

岁酱吖の 提交于 2019-12-06 11:07:26
I have 1D array of pixel values and i can get red, green and blue this way. int rgb[] = new int[] { (argb >> 16) & 0xff, //red (argb >> 8) & 0xff, //green (argb ) & 0xff //blue }; I know width height of image as well which I want to create. So, in total I have following data. 1) width of new image 2) height of new image 3) one dimension array of pixel value. My supervisor has advised me to use createRaster method but function arguments are hard to understand for me. Can you suggest me some simple code? Thanks. npinti As stated in this previous SO post: public static Image getImageFromArray(int

gdal ReadAsarray for vrt extremely slow

巧了我就是萌 提交于 2019-12-06 08:49:02
问题 I am trying to simply subtract two rasters and save the result in another raster. One of the input images is a tif-file, the other is a vrt-file. (Output is tif) The files are very big, so I open them, divide them into tiles and run through each of them and then subtracting. The problem is that it is extremely slow! import gdal import numpy as np rA = gdal.Open(raFileName) rB = gdal.Open(rbFileName) nodataA = rA.GetRasterBand(1).GetNoDataValue() nodataB = rB.GetRasterBand(1).GetNoDataValue()

Raster of Latitudes and Longitudes

痴心易碎 提交于 2019-12-06 06:39:30
问题 Given raster object r , how can I create a new raster with the same extent and resolution, with cell values equal to the latitude (or longitude) of the corresponding cell in r ? For example, r might look like: r <- raster(matrix(runif(100), ncol=10)) 回答1: If your question is about create a new raster object which has the same extent and resolution of another raster object you can use command template template is Raster* or Extent object used to set the extent (and CRS in case of a Raster*

Function to sum each grid cells of raster stack using other rasters as an indicator

∥☆過路亽.° 提交于 2019-12-06 06:12:36
## input raster s <- stack(list.files("~/dailyraster", full.names=TRUE)) # daily raster stack r_start <- raster("~/stackSumSTART.asc") # this raster contain starting Julian day r_end <- raster("~/stackSumEND.asc") # this raster contain ending Julian day noNAcells <- which(!is.na(r[])) # cell numbers which contain values ## dummy raster x <- r x[] <- NA ## loop for (i in noNAcells) { x[i] <- sum(s[[r_start[i]:r_end[i]]][i]) } I would like to create a function like stackApply() , but I want it to work on a cell basis. Above is a for() loop version and it works well, but it takes too much time.

Estimate the gradient of an undefined surface

余生长醉 提交于 2019-12-06 03:37:22
问题 I want to estimate the gradient (slope and aspect) of an undefined surface (i.e., the function is unknown). To test my methods, here is the test data: require(raster); require(rasterVis) set.seed(123) x <- runif(100, min = 0, max = 1) y <- runif(100, min = 0, max = 1) e <- 0.5 * rnorm(100) test <- expand.grid(sort(x),sort(y)) names(test)<-c('X','Y') z1 <- (5 * test$X^3 + sin(3*pi*test$Y)) realy <- matrix(z1, 100, 100, byrow = F) # And a few plots for demonstration # persp(sort(x), sort(y),

Convert Bitmap to Polygon - (Reverse-Rasterizing)

眉间皱痕 提交于 2019-12-06 03:21:47
问题 Given a bitmap image with some blots of solid color on it, what algorithm would you employ to construct polygons in the same shape as the blots? This can be done in multiple steps: a high-resolution polygon could be later cut down by a best fit algorithm. Bonus points if you can tell me how to cut the resulting polygons into convex components so that they can be rendered in OpenGL without problems. 回答1: Reverse rasterizing is referred to as vectorizing. The algorithms are generally quite

Performing loops on list of lists of rasters

扶醉桌前 提交于 2019-12-06 02:06:29
问题 Need solution, help will be much appreciated. In the following code I am creating three rasters. I then create a random number of point locations on this raster and I am receiving a list of three matrices with coordinates of those random locations called samples . I then take those locations and sample raster values to receive samplevalues . What I want to change is that I want to create a set of 100,150,200 and 250 random point locations ( numberv ). So after generating these locations and

Relassify continuous raster data into binned classes with discrete colors

[亡魂溺海] 提交于 2019-12-06 01:27:06
问题 I would like to: Reclassify the raster ras into nine classes using reclassify Provide a colorkey with values written beside each colour (see sample plot below). The colorkey should not be split, as in the sample plot, but rather shown as a single colour ramp with 9 colours. Display the data using levelplot function (this I can do) Thanks for your help. AEZ library(rasterVis) Please use these colors: col <- colorRampPalette(c("yellow4", "yellow", "orange", "red3", "darkred")) levelplot

how to convert longitude from 0 - 360 to -180 - 180

℡╲_俬逩灬. 提交于 2019-12-06 00:59:41
问题 The longitude in CMIP5 future climate data is in 0 - 360 degree. How can I convert it to -180 - 180 degree using the raster package? I tried with shift(r0,-180) and shift(r0,-360) . It does not work. Any help will be appreciated. r0 here is a raster. 回答1: Try rotate() . Its help page even mentions its utility with the type of data you're dealing with: Rotate a Raster* object that has x coordinates (longitude) from 0 to 360, to standard coordinates between -180 and 180 degrees. Longitude

extract() data from raster with small polygons - rounded weights too small

╄→尐↘猪︶ㄣ 提交于 2019-12-05 23:23:46
问题 Using R, I am trying to extract data from a raster layer using a polygon layer. The polygons are much smaller than the raster cells: Now I call extract() from raster library: a <- extract(raster, polygons, weights = TRUE, small = TRUE) a # ... # [[1551]] # value weight # 209 0.03 # top left cell - more than 50% of the polygon area There are two problems - the weight is the proportion of the cell area covered by the polygon, and the weights are rounded to 1/100. In my case, only the top left