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

Origin, resolution and coordinates of SpatRaster are (slightly) modified after writing/reading with some file formats, not all

When writing then reading a SpatRaster with certain file formats (ESRI .hdr labeling format, netCDF and ENVI, but not GeoTIFF or Erdas HFA), the raster origin, resolution, and coordinates change slightly. Enough for equality tests for these…
0
votes
3 answers

How to get a block of values out of a terra raster?

How to reproduce, for terra rasters, the function getValuesBlock of the raster package? For example, how to translate into the terra package the example given in the documentation of the getValuesBlock of the raster package? logo <-…
0
votes
2 answers

Assign one of three values at random to a raster cell given constraints

I'm working on some post processing of a very large raster (437760000 cells) using other raster layers of the same extent/crs for constraints. The code is working for the most part but I'm running into an issue. r1[r2== 6 & r3>= 40 & r3<= 60] <-…
slaca
  • 1
0
votes
1 answer

File extensions automatically recognized by writeRaster and rast for writing/reading raster files?

How could I get the list of file extensions automatically recognized by writeRaster and rast functions, for writing and reading different raster file formats?
0
votes
1 answer

Prefixing the c function from terra

In R, I can prefix functions with the name of the package they belong to (e.g., dplyr::select). Nevertheless, I am having problems when doing this with c from the terra package. I can do it fine with base::c (should I want to): base::c(1, 2, 3) #…
Dan
  • 11,370
  • 4
  • 43
  • 68
-1
votes
0 answers

Defining minimum and maximum for R terra color palette

Title says all: I would like to plot a SpatRaster map using terra so that all values below a certain threshold have a color, all above another threshold have another color (say, all values below -2 are red and all values above 10 are blue), with a…
vladbadu
  • 1
  • 1
-1
votes
0 answers

which.min function to a raster matrix?

a raster file: library(terra) ff <- system.file("ex/elev.tif", package="terra") rasf<- rast(ff) rasf=rasf/100 I want to classify the values of rasf according to the best match with values of vec , using which.min vec=c(0.1, 1, 3.5,…
Tpellirn
  • 660
  • 4
  • 11
-1
votes
1 answer

How to read output of crs() in the Terra package in R

I have a SpatRaster and I want to figure out the EPSG code of it. I have used the crs() command and I got the following output: PROJCRS["unknown", BASEGEOGCRS["NAD83", DATUM["North American Datum 1983", …
RobertoAS
  • 45
  • 6
-1
votes
1 answer

Is it possible to get the probability predictions for each class with mlr3, ranger and terra?

ML beginner here, so apologies for any wrong terminology. I have two questions. Firstly, is it possible to add an additional "unknown" class, when the probability of any one class is very low? And, secondly, how can I return the probability values…
pbengou
  • 13
  • 3
-1
votes
1 answer

How to overlay more than 2 files in r?

We can compute the mean of corresponding layers from 2 stacks like this. library(raster) s1 <- stack(system.file("external/rlogo.grd", package="raster")) s2 <- sqrt(s1) m4 <- overlay(s1, s2, fun=function(x) mean(x, na.rm=TRUE)) I have several…
Tpellirn
  • 660
  • 4
  • 11
-1
votes
1 answer

How to Zonal Statistic NDVI (tif) from land cover(shp) with multiple features in R

I have many NDVI tifs and a land cover shp with multiple features. I want to know average NDVI in forest or grass and other land cover. I have tried terra::extract, but it extract by the CODE1 feature,not land TYPE u…
jackywang
  • 75
  • 6
-1
votes
2 answers

Generate random rasters with grid values summing up to a number

How do I generate 5 random rasters with values within defined bounds (different for each raster), and with pixel values summing up to 1? Here are the bounds xmin <- c(0, 0, 0, 0, 0) xmax <- c(26.0, 78.6, 14.4, 39.4, 70.8) Can I also follow the…
jmutua
  • 290
  • 1
  • 12
-1
votes
2 answers

Can to setup environment variable during build time

We are using Drone and terraform for CI/CD for react application. Can you please help me to create environment variable dynamically during build.
M M
  • 47
  • 3
-2
votes
2 answers

Which package should be used for arithmetic functions on large datasets, terra or raster?

I need to do calculations on a lot of big rasters(28000 cells, 181 layers). I tried my code on a small subset (24cells, 181 layers). I took help from this forum to optimize as much as I could. Now I used bricks in raster package because I read that…
1 2 3
34
35