Questions tagged [terra]

Use this tag for questions related to functions from the terra package for spatial data analysis. For Terra (Luna) blockchain protocol, use terra-blockchain tag instead

is an package for spatial data analysis, especially raster data. The package also has general raster-related functions, such as for creating, reading, manipulating, and writing raster data. terra is written in and is intended to replace the raster package in the future because it is simpler and much faster. Tutorials are available at https://rspatial.org/terra.

Scope of questions

This tag should be used for programming-related questions about the R terra package. Including a minimal reproducible example of raster data in your question will increase your chances of getting a timely, useful answer. Questions should be specific to the functions in the terra package. Questions should not use the r-raster tag unless they relate specifically to the raster (i.e., r-raster tag) package and not just raster spatial data analysis.

Repositories

Maintainer

525 questions
0
votes
2 answers

Efficiently create many polygons

I want to create polygons inside an apply and want to do this as quickly as possible from a matrix of coordinates. I have some code and realized this is one of the slowest parts of my code. How can I do this efficiently? I tried two different…
Zoe
  • 906
  • 4
  • 15
0
votes
1 answer

R - Computing seasonal raster based on specified months in R

I have monthly rasters for multiple years from which I would like to compute seasonal sum based on specific months (October to February). library (terra) #create rasters r1 <- rast(nrows=50, ncols=50) rr <- lapply(1:36, function(i) setValues(r1,…
0
votes
1 answer

Calculate polygon area for each land cover type (using spatraster object)

I'm trying to calculate the area (and ideally percentage) of a 6 bands within a spatraster (land.sub). I made this spatraster by cropping an original land cover raster to polygon data (which represent presence of seagrass). I'm trying to work out…
Alex White
  • 21
  • 2
0
votes
1 answer

How to calculate regression between three stacks in R?

To compute local regression, that is, a regression model for each grid cell (pixel), you can do use library(terra) s <- rast(system.file("ex/logo.tif", package="terra")) ## the 1 is to get a slope. ## 1:nlyrs(s) is the independent variable X…
Tpellirn
  • 660
  • 4
  • 11
0
votes
1 answer

reading in tiff files and matching them based on name

I am using R 4.2.0 and am trying to read a series on tif files nested in different folders. My folder set up is as follows: scenario 1/ global_model/ high_level/ scenario1_highlevel_2020.tif scenario1_highlevel_2030.tif …
0
votes
1 answer

Increase raster label size for axis, legend and title using terra

How can I increase the size of labels of legend break, axis and plot title using terra package. The plot created below has such small labels that I can't read them at all. r1 <- rast(ncol=10, nrow=10, xmin=-150, xmax=-80, ymin=20, ymax=60) r2 <-…
89_Simple
  • 3,393
  • 3
  • 39
  • 94
0
votes
1 answer

How to multiply a multi-layer raster (457 bands) with a one-layer raster (values of 0 and 1 ) in R with terra package?

I want to multiply two rasters in R with 'terra'. Raster1 has 457 bands with EVI values meanwhile raster2 is a one-layer raster -of almost same extent- with binary values (0 or 1). The result that I want to achieve is to get raster1 (with the 457…
val
  • 1
0
votes
2 answers

Create polygon from outermost point spatial coordinates

I have a large dataframe of point coordinates and I am trying to make a polygon out of the edge of the coordinates. Some of the points fall near the middle, so I do not want those points to shape the boundary of the polygon created. These are…
Ryan Utz
  • 51
  • 1
  • 6
0
votes
1 answer

Normalise raster for individual polygons

library(raster) library(rnaturalearth) library(terra) r <- raster::getData('CMIP5', var='tmin', res=10, rcp=45, model='HE', year=70) r <- r[[1]] shp <- rnaturalearth::ne_countries() newcrs <- "+proj=robin +datum=WGS84" r <- rast(r) shp <-…
89_Simple
  • 3,393
  • 3
  • 39
  • 94
0
votes
1 answer

R raster package no longer reads E00GRID files?

I updated R and all of my packages recently and am no longer able to read files that previously worked. Specifically, I am trying to read in ArcInfo Exchange grid files (.e00) using the raster package. Has anyone else encountered this issue or know…
Jes
  • 1
  • 1
0
votes
1 answer

How to change SpatRast resolution using res and projectRaster in library(terra) correctly?

I have a raster file of sea surface temperatures from HadISST at 1x1 resolution. Previously I've re-grid to 0.5 x 0.5 using cdo(csl("remapbil","global_0.5"), inputfile, output file, debug=FALSE) from cdo via climateoperators but I'd like to explore…
0
votes
1 answer

Arthematic operations using rasters throwing errors using terra package not with raster package

I am trying to do some calculation on raster using following code library(terra) f <- system.file("ex/elev.tif", package="terra") r <- rast(f) r_n <- (r - global(r, fun = "min", na.rm=TRUE))/ (global(r, fun = "max", na.rm=TRUE) - global(r, fun…
UseR10085
  • 7,120
  • 3
  • 24
  • 54
0
votes
1 answer

Aggregating fine resolution raster to coarser resolution such that pixel value of coarse pixel is proportion of unique pixel value in fine res raster

I have a raster with pixel values 1 or NA (first image below) with specifications includedr after image. I want to coarsen to 10km*10km resolution such that the new pixel value in the final coarse pixel is proportion of pixels with value=1 (last…
tg110
  • 401
  • 1
  • 3
  • 15
0
votes
1 answer

How to convert a Terra rawstring into a Lua string?

I have some C code that returns char *, or rawstring in Terra. How can I pass a value of this type to Lua and use it as a normal string? If it matters, the rawstring is allocated on the heap (and I won't need to free it).
Renato
  • 12,940
  • 3
  • 54
  • 85
0
votes
1 answer

Unable to add legend for point shapefile using terra R pakage

I want to add legend for point shapefile plotted on top of a raster. I am using the following code library(terra) f <- system.file("ex/elev.tif", package="terra") r <- rast(f) plot(r) d <- data.frame(lon=c(6.0,6.1,6.2,6.2), lat =…
UseR10085
  • 7,120
  • 3
  • 24
  • 54