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
1 answer

Are there web browser packages for flutter that allow for callbacks?

I'm tasked with integrating with a service (Terra) that implements launching a web view to log into said service. Once the user logs in, it returns a url with params I need for further processing. However, my problem is that once I'm logged in…
nyphur
  • 2,404
  • 2
  • 24
  • 48
0
votes
1 answer

How to get the the dominant class when extracting from a raster?

My aim was to get the dominant land cover class for a given area using the terra package. In principle, this can be done with the function extract as for example library(terra) library(rworldmap) r <- rast(nrows=10, ncols=10) values(r) <- sample(3,…
0
votes
1 answer

R packages "terra" and "raster" make R crash when charging library

I first had the same issue than this post : R packages "raster" fail to upload while searching for "terra" last version (problem with terra updating) but now, with the solutions I've got there I face a new problem : When I charge the library of…
0
votes
1 answer

How to avoid memory issues when creating a mosaic of raster tiles using terra?

I have a list containing 375 raster tiles that I would like to mosaic into one raster: filelist_lc <- list.files("Northern_Land_Cover_2000/") lc_2000_tiles <- lapply(filelist_lc, rast) > lc_2000_tiles[[1]] class : SpatRaster dimensions :…
canderson156
  • 1,045
  • 10
  • 24
0
votes
1 answer

Can different functions be used to extract different types of layers of a raster using terra::extract?

My goal is to extract data from a raster for a set of polygon locations. The raster has many numeric variables and some categorical. I would like to extract the values conditional on this, e.i., if the variable is numeric get the mean for each…
0
votes
1 answer

Problem using terra::extract results present nan value

I would like to extract values from rasters to points. I am using the terra and extract() function. The script works but I noticed that for some rows (about 100) the result of the extract function is the value "nan". No points are outside rasters. I…
matt85
  • 49
  • 1
  • 7
0
votes
0 answers

Translating JavaScript into R: secondary sentinel products

I'm trying to translate the following JavaScript into R but having problems: /* Author of the script: Carlos Bentes */ // Normalized Difference Vegetation Index var ndvi = (B08-B04)/(B08+B04); // Threshold for vegetation var veg_th = 0.4; //…
0
votes
1 answer

Turning a SpatRaster object to a SpatialGridDataFrame

How to convert a SpatRaster object (from the terra package) to a SpatialGridDataFrame object? r <- terra::rast(matrix(runif(10), 5, 5)) as(r, "SpatialGridDataFrame") Error in as(r, "SpatialGridDataFrame") : no method or default for coercing…
Junitar
  • 905
  • 6
  • 13
0
votes
2 answers

How can I subset a raster by conditional statement in R using `terra`?

I am trying to plot only certain values from a categorical land cover raster I am working with. I have loaded it in to R using the terra package and it plots fine. However, since the original data did not come with a legend, I am trying to find out…
apple
  • 387
  • 1
  • 14
0
votes
1 answer

aggregate raster with custom function fails

I'm doing a pretty basic aggregation operation using aggregate from the terra package. The main idea is to calculate the percentage of pixels with values over the whole number using the following function: nofun = function(x){…
Nico
  • 191
  • 1
  • 6
0
votes
2 answers

How can I create a data frame containing raster data combined, seperated by shapefiles?

I took a statistics class in which we worked with global temperature raster data and then selected the data we needed for a specific country by using shapefiles. We learned quite a few interesting steps to work with the data, but I never learned how…
0
votes
1 answer

Units lost when saving and reopening raster in terra

When I save and reopen a raster in terra, I am losing the assigned units. Perhaps there are some filetypes that can save them while others can't, but I haven't found documentation of that. library(terra) A <- rast( nrows=10, ncols=10, xmin=0,…
Jim Worrall
  • 466
  • 3
  • 11
0
votes
1 answer

How to make a shiny app that allows to draw multiple polygons on raster images?

I want to develop a shiny app where users can draw a polygon on a raster image. As soon as the user finishes drawing a polygon, I want the app to show them a table of chosen pixels. For example, terra provides a function draw that can be used as…
bird
  • 2,938
  • 1
  • 6
  • 27
0
votes
1 answer

Extract values from layers in terra package

I have a terra::rast with n layers. I would like to extract values for certain layers only with the package terra (I prefer answers with this package rather than raster). It seems I do not get how to use the argument layer in the function…
mistral
  • 35
  • 7
0
votes
1 answer

terra package producing weird warnings during extracts

I have been having a problem using the terra package. When I perform raster extracts on a polygon data set with weights=TRUE, I sometimes get many warning messages. From interpreting the warnings, it seems like perhaps terra is trying to write…
ksweet
  • 93
  • 5