r-raster

How can I write parts of a list into one data frame?

梦想与她 提交于 2019-12-11 16:55:48
问题 I want to write a single df with the freq of 150 raster objects (partly answered in: Count freq of multiple raster objects in R) I have created a list of all the raster files with spatial.tools::list.raster.files() and then called lapply(ls$raster,freq) Now I have a list containing 150 entries that contain a freq matrix for every raster file. I am only interested in $Band.1[,"count"]) however. For a single entry of the list I can create a df for counts with as.data.frame(all[[1]]$Band.1[,

Why won't writeRaster save a 4390x4390 raster?

蓝咒 提交于 2019-12-11 12:53:37
问题 I'm trying to save a raster in R, which was cropped from GLC2000. The resulting raster has 4390 rows and 4390 cols, covering Brazil and part of South America. The command to save it (as a GeoTIFF) is either writeRaster(r1,'Raster1.tif') or writeRaster(r1,'Raster1.tif','GTiff') Both keep trying to save the file for several hours, but they don't even create the file, much less finish the write process. I doubt that's because of the size of the file (I think the file should at least start saving

Issue using saveRDS() with raster objects

点点圈 提交于 2019-12-11 12:12:34
问题 I'm trying to use saveRDS() to save a large number of lists each containing a raster layer and a list with metadata. It worked fine when the raster layer was extracted from a ncdf file, but when the original file is an ascii file, saveRDS() only writes a pointer to the original file instead of writing the values to the end file. Here's a condensed version of what's going on: require(raster) mf <- raster('myfile.asc') meta <- list(mylonglistofmetadata) res <- list(mf, meta) saveRDS(res,

Count freq of multiple raster objects in R

故事扮演 提交于 2019-12-11 12:10:02
问题 I want to write a df with the freq of 150 raster objects. I know I can read individual raster objects with raster_x <- raster::raster() I can further get the freq with raster_freq_y <- raster::freq(raster_x) After that I can bind the freq outputs of multiple raster objects to a df with cbind.data.frame(raster_freq_x, raster_freq_y) What I dont know is how to do this for 150 raster objects in one go? Should I use a loop? If so what kind of loop would make sense? Any help is appreciated. 回答1:

R focal (raster package): how to apply filter to subsets of background data?

给你一囗甜甜゛ 提交于 2019-12-11 10:27:06
问题 I was wondering if any of you could help me with the following task dealing with the focal() function in the R raster package. By default, the focal() function will run through each cell of a given raster ('background' raster hereafter) and apply a given function to the neighboring values as defined by a user-defined moving window. In order to optimize and speed up my computation on large rasters/study areas, I would like to apply this function (filter) only when the 'background' raster has

RasterLayer 16-bits into a RasterLayer 8-bits

廉价感情. 提交于 2019-12-11 10:02:05
问题 I have a tried to convert a RasterLayer 16-bit into a RasterLayer 8-bit in R, but I did not have success. Any ideas ? Thanks! 回答1: If you want to convert your RasterLayer from 16-bit to 8-bit you need to stretch your values into the 8-bit interval (0-255 unsigned) first. Then you can save it as an 8bit image: #sample raster library(raster) ras16b <- raster(x=matrix(as.integer(rnorm(180*180,1000,50)),180,180)) #convert to 0-255 using the calc. function and basic raster algebra ras8b <- calc

Calculate selected area from stacked raster object

徘徊边缘 提交于 2019-12-11 06:48:16
问题 As I have only recently started using R for spatial analysis, and I am not a geographer or spatial data specialist by any means, I have a -what I presume to be- relatively simple question. I am trying to calculate the area of part of a stacked raster object that meets certain conditions. More specifically, from a dataset from the deep sea in the south Atlantic, I have stacked two raster objects (depth and slope) that are further identical in coordinate system (WGS84) and x-y (Lat-Long)

How to replicate ggplot2::geom_raster in base graphics?

可紊 提交于 2019-12-11 05:24:37
问题 tl;dr If you run both code snippets below ( note: code was previously broken, but now is fixed and has been checked on multiple computers ), you will see two plots of some raster data. One uses ggplot2 and produces a smoothed image with high-resolution coastlines that are somehow inherited from the polygons that I used to mask the raster. Without using ggplot2, we can get the smoothed image using raster::plot(... , interpolate='bilinear') or rasterImage(interpolate = TRUE) . But the

Conditional command from Raster Calculator transfer to R

偶尔善良 提交于 2019-12-11 05:06:18
问题 So far I used the following statement in the Raster Calculator of ArcGIS: Con(("Land_use.rst" == -20), "Export.rst") This calculates a new Raster which only contains the Data from Export where Land_use equals -20. That is exactly what I want. But I want to automatise this in R , as I have to do it a lot of times. So far I got something like this: for (catch_dir in Dir_List) { r1 <- raster(paste0(catch_dir, '/Export.rst')) r2 <- raster(paste0(catch_dir,'/LAND_use.rst')) ### statement that

How can I extract an area weighted sum from a raster into a polygon in R?

若如初见. 提交于 2019-12-11 04:57:17
问题 I have a raster (of class "RasterLayer") which holds counts of people, N. I have polygons representing administrative boundaries (of class "SpatialPolygonsDataFrame"). I want to extract the values from the raster layer into the polygons, in a way that is weighted by the proportion of the area of the raster tile which overlays the polygon. Say there are four raster tiles, with values (4, 8, 12, 16) overlapping a single polygon. If 25% of each raster overlaps with the polygon, I would expect