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
3
votes
0 answers

signature verification failed; please verify account number and chain-id: unauthorized

You don't want to know how many hours I've spent trying to figure this one out. I'm trying to send a broadcast to the Cosmos Blockchain, via the Terra Pisco/Rebel1 Api. LUNA2: https://pisco-lcd.terra.dev/swagger/#/ LUNC:…
Dan Gerchcovich
  • 168
  • 5
  • 12
3
votes
2 answers

R: calculate Euclidean distance between two raster layers pixels

I have two raster layers for same area. I need to find the Euclidean distance between cell of coarse resolution raster and cell of fine resolution raster that fall within each cell of the pixels from my coarse resolution raster. For example: The…
Nikos
  • 426
  • 2
  • 10
3
votes
1 answer

How to identify raster cells that intersect with lines in R?

Problem I have Spatial Lines (as an terra::vect() object) that I would like to intersect with a Raster (terra::rast()) in order to identify the cells by id that each line intersects. As an output I want a long form data.frame with columns line_id…
chamaoskurumi
  • 2,271
  • 2
  • 23
  • 30
3
votes
2 answers

return polygon nearest to a point using terra in R

I am doing a point in polygon analysis library(terra) library(rnaturalearth) crdref <- "+proj=longlat +datum=WGS84" lonlat<- structure(c(-123.115684, -81.391114, -74.026122, -122.629252, -159.34901, 7.76101, 48.080979,…
89_Simple
  • 3,393
  • 3
  • 39
  • 94
3
votes
2 answers

How to change a raster to a specific spatial resolution?

I would like to change the resolution of a raster. For example, let’s take this Landsat 7 images at ~ 30m resolution. library(terra) #> terra 1.5.21 f <- system.file("tif/L7_ETMs.tif", package = "stars") r <- rast(f) # 30m x 30m…
Philippe Massicotte
  • 1,321
  • 12
  • 24
3
votes
1 answer

R terra:: subst not reclassifying correctly?

the terra::subst function appears to be returning incorrectly reclassified raster values, when using numeric vectors: require(terra) # dummy SpatRast set.seed(234) r1 <- rast(xmin=0, xmax=100, ymin=0, ymax=100, res=1, val=sample(1:10, 100^2,…
Sam
  • 1,400
  • 13
  • 29
3
votes
2 answers

How can I reclassify a categorical raster in terra using category names

I'd like to be able to merge two categories in a categorical raster. The only solution I've figured out so far uses the level index number, not the name of the category. How could I do this using the name of the category? library(terra) m <-…
canderson156
  • 1,045
  • 10
  • 24
3
votes
1 answer

NULL value passed as symbol address error in foreach loop R

I have never had problems with this before, but I am running into this error when trying to use a foreach loop in R: "Error in { : task 1 failed - "NULL value passed as symbol address". It is next to impossible for me to produce a small,…
user8229029
  • 883
  • 9
  • 21
3
votes
2 answers

Loading some packages with Rstudio server does not work, while it works with R server

I am using Rstudio server on a remote server and I have some packages already installed. When I try to load libraries like raster or terra using Rstudio server, I get error: > library(terra) Error: package or namespace load failed for ‘terra’ in…
bird
  • 2,938
  • 1
  • 6
  • 27
3
votes
1 answer

Subset a raster using row/column index in terra

I'm trying, in the package terra, to subset a raster by row and column numbers. Apparently that is easy in raster, at least without a geographic extent and crs: Subset a raster using row/column index. But I can't get it to work in terra. There has…
Jim Worrall
  • 466
  • 3
  • 11
3
votes
2 answers

terra function to extract all bands of one variable? (equivalent to brick('x', varname='y'))

I have a netcdf file that contains 79 variables, and for each variable there are 365 bands (one for each day of the year). I want to read all bands of one variable (i.e., a raster with 365 ayers). With the 'raster' package this would work as…
Lena
  • 311
  • 2
  • 10
3
votes
1 answer

function rast of terra package not working on a RasterLayer

I tried to read a DEM raster using getData (from the raster package), then convert the RasterLayer to a SpatRaster (terra package). First step worked, but the second one failed. library(raster) library(terra) (alt <- getData('alt', country='DEU',…
2
votes
0 answers

Calculating Thornthwaite Evapotranspiration on Raster Data more efficiently

I'm currently running Thornthwaite Evapotranspiration calculation for huge raster stacks. I'm following a solution by Robert Hijmans from another stack overflow thread: Thornthwaite evapotranspiration on a raster dataset . Error formula not…
thoo92
  • 21
  • 2
2
votes
1 answer

Area of each cell covered by polygons

Is there a way/function to calculate the proportion of each raster cell covered by a polygon? The polygons are usually larger than single cells and the landscape I'm working on is pretty big. I'll like to do it without converting the raster into…
Guillermo.D
  • 399
  • 2
  • 14
2
votes
0 answers

Error loading r package within conda environment: libproj.so.15: cannot open shared object file

I am creating the following conda environment: $ mamba create -n mexico -c conda-forge -c bioconda -c R r-base=4.2.3 r-data.table=1.14.8 r-terra=1.5_21 __ __ __ __ / \ / \ / \ / \ …
1
2
3
34 35