Questions tagged [r-raster]

raster is an R package for geographic data analysis and modeling.

Other resources

Related tags

1217 questions
8
votes
1 answer

R: how to write a raster to disk without auxiliary file?

I'm writing a dataset to file in ERMapper format (.ers) using the Raster package in R, but I'm having issues with the resulting .aux.xml auxiliary file (which I'm actually not interested in). Simple example: rst <-…
dsp542
  • 83
  • 3
8
votes
0 answers

coord_map() combined with geom_tile() is very slow

I'm plotting some hemispheric fields with ggplot2 and when I try to project them into a stereographic projection it takes ages to render. This is a minimal example: lat <- seq(-87.159, -2, by = 3.7) lon <- seq(0, 360, by = 3.75) month <- 1:12 gdata…
Elio Campitelli
  • 1,408
  • 1
  • 10
  • 20
8
votes
1 answer

Change raster values using spatial polygons

To change raster values under SpatialPoints you can simply use [ . r <- raster(system.file("external/test.grd", package="raster")) rTp <- rasterToPoints(r, spatial = T) set.seed(666) rTpS <- rTp[sample(1:length(rTp), 500),] plot(r) plot(rTpS, add…
loki
  • 9,816
  • 7
  • 56
  • 82
8
votes
1 answer

"Globe"-shaped map of Russia

I draw a map of regions of Russia using GADM data: setwd("~/Desktop/Master thesis/") library(sp) library(RColorBrewer) library(raster) data <- getData('GADM', country='RUS', level=1) #exclude columns I don't need data <-…
MariaBee
  • 83
  • 3
8
votes
4 answers

A faster function to lower the resolution of a raster R

I am using the raster package to lower the resolution of big rasters, using the function aggregate like this require(raster) x <- matrix(rpois(1000000, 2),1000) a <-raster(x) plot(a) agg.fun <- function(x,...) if(sum(x)==0){ …
Leosar
  • 2,010
  • 4
  • 21
  • 32
8
votes
3 answers

Combining polygons and calculating their area (i.e. number of cells) in R

I have a simple raster (created with R-package: raster). Using the function "rasterToPolygons" I get polygons of all raster cells that contain the value "1": library(raster) dat = list() dat$x = seq(1.5, by = 10, len = 10) dat$y = seq(3.5, by = 10,…
Alex Z
  • 83
  • 4
8
votes
1 answer

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

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 # ... #…
Tomas
  • 57,621
  • 49
  • 238
  • 373
7
votes
2 answers

Add border to rasterImage

Here is a gradient color legend I created using rasterImage: colfunc <- colorRampPalette(c("red", "blue")) legend_image <- as.raster(matrix(colfunc(20), ncol=1)) plot.new() rasterImage(legend_image, 0.9, 0, 1, 1) lbsq <- seq.int(0, 1, l=5) …
Patrick
  • 1,057
  • 9
  • 23
7
votes
1 answer

Using mosaic in r to merge multiple geotiff

I have 50 geotiff files in the same folder. All of them represent elevation data in different parts of the world. I would like to merge certain geotiff files, and I found mosaic in R might help us. I have moved those geotiff into the same folder,…
Bing-Hong Huang
  • 125
  • 1
  • 9
7
votes
1 answer

writeRaster output file size

I have a function that reads a multi-band image in as a raster brick object, iterates through the bands doing various calculations, and then writes the raster out as a new .tif. All of this works fine, but the file size of the new image file is…
Danple
  • 111
  • 2
  • 6
7
votes
1 answer

Rscript : Why is Error in UseMethod("extract_") : being indicated when attempting to use raster::extract?

I attempting to use raster package's extract method to extract values from a Raster* object. RStudioPrompt> jpnpe <- extract(jpnp, jpnb, fun = mean, na.rm = T) where jpnp is the raster object and jpnb is SpatialPolygonsDataFrame However the…
KK.
  • 693
  • 6
  • 15
6
votes
1 answer

leaflet side-by-side for 2 raster images in R

{leaflet.extras2} implements the leaflet side-by-side plugin and provides this minimal example: library(leaflet) library(leaflet.extras2) leaflet(quakes) %>% addMapPane("left", zIndex = 0) %>% addMapPane("right", zIndex = 0) %>% …
Rich Pauloo
  • 7,734
  • 4
  • 37
  • 69
6
votes
1 answer

Why do terra::cellSize() and raster::area() produce different estimates of raster cell area?

I just noticed that terra::cellSize() produces cell area estimates that do not match those produced by raster::area(). First, why do these two methods not provide the same answer? Second, which estimate is most accurate? See example…
6
votes
1 answer

Reading in multiple rasters in terra package

I'm changing my spatial workflow to use the terra package instead of the raster package. With the raster package I used to read in multiple rasters directly into a stack. filelist_temp <- list.files(datapath("Climate/World Clim 1 yr Monthly…
canderson156
  • 1,045
  • 10
  • 24
6
votes
0 answers

Weird streaks when working with a large Raster

I have a large elevation raster from the ASTER database made by using raster::mosaic(). Each tile represents a one-degree by one-degree portion of the earth with an estimated raster resolution of 30m^2. I include the code that I used to mosaic them…
1
2
3
81 82