raster

How can you crop raster layers in R in a batch and change projection

时间秒杀一切 提交于 2019-12-04 18:05:53
I was working with spatial data to get ready for analyses - I have a DEM at the desired extent of my study area, though I have ~39 other layers at the national scale (US). Is there a way to crop all of these 39 layers to the same extent as the DEM at once? Also, I will be overlaying the output with other layers in a different projection. Is it possible to adjust the projection and pixel size of the output layers? I am trying to use freeware as much as possible for my data manipulation... I had the problem above, but have written a function in R to do all of this in a batch - see below. I had

NetCDF to Raster Brick “Unable to find inherited method for function 'brick' for 'ncdf4'”

两盒软妹~` 提交于 2019-12-04 17:12:48
Really simple problem with the raster package, also using ncdf4 to load in an ECMWF Era-Interim Netcdf file. Simply doing this: a <- nc_open("SSTs.nc") B <- brick(a, varname="sst") Returns this: Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘brick’ for signature ‘"ncdf4"’ The file is just SST data over the whole globe, for 1 month (Jan2016). When I convert it into an array (i.e. extract dimensions/variable, and convert time to UTC, shove it into an array) I don't get the same error, but the raster package says it supports .nc files straight in (so

Global Raster of geographic distances

删除回忆录丶 提交于 2019-12-04 16:31:54
Im wondering if someone has built a raster of the continents of the world where each cell equals the distance of that cell cell to the nearest shore. This map would highlight the land areas that are most isolated inland. I would imagine this would simply rasterize a shapefile of the global boundaries and then calculate the distances. You can do this with raster::distance , which calculates the distance from each NA cell to the closest non- NA cell. You just need to create a raster that has NA for land pixels, and some other value for non-land pixels. Here's how: library(raster) library

Raster of Latitudes and Longitudes

限于喜欢 提交于 2019-12-04 14:32:20
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)) 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* object). If not NULL, arguments xmn, xmx, ymn, ymx and crs (unless template is an Extent object) are ignored r

Raster map with discrete color scale for negative and positive values R

不打扰是莪最后的温柔 提交于 2019-12-04 13:39:51
问题 I have two dataframes which I will like to map. The dfs have the same xy coordinates and I need a single colorbar with a visible discrete color scale for both dfs like the one shown here. I would like the colors in the colorkey to match the self-defined breaks. a more general solution that can be applied outside this example is much appreciated The RdYIBu color palette from the RcolorBrewer package is what I am after. My code so far: library(rasterVis) ras1 <- raster(nrow=10,ncol=10) set.seed

can raster create multi-layer objects with different modes?

会有一股神秘感。 提交于 2019-12-04 13:34:19
问题 Can a raster object (in R) have layers of different mode (data type)? On the face of it it seems we are always forced to one type: library(raster) ## create a SpatialPixelsDataFrame with (trivially) two different "layer" types d <- data.frame(expand.grid(x = 1:10, y = 2:11), z = 1:100, a = sample(letters, 100, replace = TRUE), stringsAsFactors = FALSE) coordinates(d) <- 1:2 gridded(d) <- TRUE ## now coerce this to a raster brick or stack and our "a" is crushed to numeric NA all(is.na

gdal ReadAsarray for vrt extremely slow

淺唱寂寞╮ 提交于 2019-12-04 12:25:34
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 = gdal.GetDriverByName('GTiff').Create(outputFileName, ncols, nrows, 1 ,gdal.GDT_Float32,[

Android alternative to java.awt (BufferedImage and Raster)

99封情书 提交于 2019-12-04 12:03:54
问题 for my final year project I am developing an android app that can capture the image of a leaf and identify what type of tree it came from. I have a nearly completed PC version (developed in java) and i am starting the process of porting it to android. Although BufferedImage and Raster make up a key part of my program, this is a problem because java.awt is missing in android, so this means i have to alter the library. I am using a library that was developed by my lecturer, the method below

Fastest way to extract a raster in R (improve the time of my reproducible code)

风格不统一 提交于 2019-12-04 11:47:25
I'm wondering if I have maximized the speed at which a mean of an area buffered around a point in a raster can be extracted. Can performance be improved any further on these LOCALLY? I use parallel mclapply already, and I know I could get further gains by setting up and running this on a cluster (use a cluster or get more cpu's is not the answer I'm looking for). Replicate some data: library(raster) library(parallel) library(truncnorm) library(gdalUtils) library(velox) library(sf) ras <- raster(ncol=1000, nrow=1000, xmn=2001476, xmx=11519096, ymn=9087279, ymx=17080719) ras[]=rtruncnorm(n=ncell

Check if a file contains raster or vector elements? (pdf, eps, ai)

烈酒焚心 提交于 2019-12-04 10:47:05
Is there a way to check if a file has raster elements in it? I would be interested to do this for the .pdf, .eps and .ai formats. If the file is only vector I am converting it to .svg and if it has some raster elements I have to convert it to .png file. I am working in PHP but I can utilize any command line tools as well. For instance I am considering using Inkscape to do the actual conversion. No there is not. The following is a theoretical computer science proof for eps which proofs, that the asked property can not be computed. PostScript(ps) and also Encapsulated PostScript(eps) are turing