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
11
votes
2 answers

What should I actually be doing in response to this warning? "Please note that rgdal will be retired by the end of 2023"

I keep noticing this message when I load the rgdal package: "Please note that rgdal will be retired by the end of 2023, plan transition to sf/stars/terra functions using GDAL and PROJ at your earliest convenience." I don't know what this means. Does…
canderson156
  • 1,045
  • 10
  • 24
9
votes
5 answers

R Crop no-data of a raster

I would like to crop the no-data part of some rasters (example of the image in 1 where no-data is in black) without defining the extent manually. Any idea?
Wraf
  • 747
  • 2
  • 10
  • 24
8
votes
1 answer

Understanding raster::extract and terra:extract

I'm having issues fully understanding terra:extract. I wish to extract average raster values for administrative GADM polygons. My raster has one single value per country. I would expect that each administrative polygon within a particular country…
Cecile
  • 527
  • 5
  • 22
7
votes
3 answers

Terra equivalent for raster::stack()?

Basically the title. I know you can read in a folder of rasters with rast() but I just want to stack two rasters that are read in separately. Thanks
Nathaniel
  • 81
  • 1
  • 6
6
votes
3 answers

Rasterize polygons based on maximum overlap (using R packages terra or stars)

I have a question concerning rasterization of polygons by maximum overlap, i.e assign the value of the polygon that has the highst area overlap with the raster cell. The real world exercise is to rasterize polygons of soil-IDs in R, in order to…
paulsw
  • 63
  • 5
6
votes
1 answer

r Terra issue with multicategorical raster. How to properly extract the categories and their values into layers without losing data?

I am working with rTerra and having an issue with the CONUS historical disturbance dataset from LANDFIRE found here:https://landfire.gov/version_download.php (HDist is the name). To summarize what I want to do, I want to take this dataset, crop and…
souma
  • 63
  • 4
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

terra package returns error when try to run parallel operations

I'm working with raster package and I try to switch to terra but for some reasons that I don't understand, terra cannot reproduce the same operation of raster when working in parallel with packages such snowfall and future.apply. Here is a…
Elia
  • 2,210
  • 1
  • 6
  • 18
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
5
votes
1 answer

warning when creating a raster from XYZ: additional columns are a problem?

I try to build a SpatRast with 2 layers, using the "xyz" reading style. It works with 3 columns as input to the rast function, but I get a warning message with 4 columns: >…
4
votes
1 answer

How to index individual layers from a SpatRaster object by time?

I found out the other day, more or less by chance, that it is possible to query layers from SpatRaster objects based on the time attribute in general (c.f. here), e.g based on years (r["2017"]) and yearmonths (r["2017-10"]). Now I wanted to…
dimfalk
  • 853
  • 1
  • 5
  • 15
4
votes
2 answers

How to count NAs using terra's global function?

I am trying to count the non-NA values in a spatRaster using the global() function from the terra package. All the functions (mean, max, sd, etc.) seem to work except for "isNA" and "notNA". For these two functions it returns this error: Error in…
ia200
  • 255
  • 1
  • 9
4
votes
2 answers

Terra R - Speed up aggregate() of raster data with custom function

I would like to use aggregate function from the terra R package to aggregate raster with a quantiles approach as aggregation function. Here below, I used the quantile function from R base to compute 50th percentile (i.e. the median) using a raster…
Adrien
  • 157
  • 8
4
votes
4 answers

Suddenly error 'Cannot create a RasterLayer object from this file.' in script that worked before

I have a script where I read a raster stored as .tif : f_treecover <- raster('Landcover_data/treecover_res_100_q.tif') The script used to run fine a few months ago, but now I get the following error message: Error in…
Lena
  • 311
  • 2
  • 10
3
votes
1 answer

Why do rgeos/sp and terra give different values for polygon area?

I am converting several functions from the sp package to terra and I have encountered an inconsistency in the calculated area of polygons. The code sample below demonstrates my issue. x = seq(0, 2 * pi, length.out = 100) circle = cbind(sin(x),…
randr
  • 255
  • 1
  • 7
1
2 3
34 35