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

Why am I losing columns when extracting raster data with ```terra::extract```?

I created a raster stack with rasters containing different vegetation measurements (i.e., canopy height, veg density). I extracted data from that raster stack to a SpatVector containing GPS points and corresponding data. The output contains the…
JLD475
  • 125
  • 1
  • 8
0
votes
1 answer

How to create a new raster in terra with same NA cells?

I need to create some new rasters by assigning values using z <- rast(x, vals = y). I would like the new raster (z) to have NA values at the same location as the old raster (x), but with the newly assigned value(s) (y) in the non-NA cells. What is…
ia200
  • 255
  • 1
  • 9
0
votes
1 answer

3D surface area of a raster map (considering topography)

How can I calculate the 3D surface area (including topography) for an elevation raster map in R, preferably with package terra? Something like the r.surf.area module of GRASS GIS, or the surfaceArea function of the R sp package, but (if possible)…
AMBarbosa
  • 250
  • 1
  • 8
0
votes
2 answers

How to rasterize a vector for area variable?

I have used many times the same process of rasterization, which works fairly well: raster <- rasterize(vect(shapefile.shp), base_grid, "my_variable") where raster is the rasterized shapefile, shapefile.shp is the original vector, base_grid is the…
Henrique
  • 135
  • 6
0
votes
1 answer

How to crop (chop) a raster with equal sizes in R

I want to crop a raster and then save each peace into a list (or another way) with the pieces of the raster. The idea: To preserve the covered area as equal for all of the pieces. To be possible for the user to set a percentage of extent area to be…
0
votes
1 answer

How to resample partially overlapping rasters using terra package in R?

I have three partially overlapping DEM rasters with different origins, resolutions (only slightly different) and extents. I know I need to use terra's resample function rather than merge or aggregate because of the different origins, etc., but I'm…
ia200
  • 255
  • 1
  • 9
0
votes
1 answer

how to properly project a rast object if extent information is missing?

I'm trying to read a HDF5 file with terra, but the extent of the grid could not be read. > rst <- terra::rast("temp.h5") Warning message: [rast] unknown extent > rst class : SpatRaster dimensions : 765, 700, 2 (nrow,…
knstr
  • 1
0
votes
1 answer

Running nested user-defined function in `terra::app()` on multiple cores

PREFACE My error is a simple "Mathematical operation applied to non-numeric argument" error, but I think this arise from how I create a suite of user defined functions and use them within the terra::app() function. I am going to describe the full…
Sean McKenzie
  • 707
  • 3
  • 13
0
votes
1 answer

Use R to create a historgram of categorical raster values? (or, create data table with lat/long values)

I am very new to R and programming in general, please forgive my forthcoming ineptitude. I am working with a large categorical raster. Essentially, every pixel shallower than 10 meters on the Great Barrier Reef is assigned a value: 11,12,13, or 15.…
TRD
  • 3
  • 2
0
votes
0 answers

send terrafrom output of ressources created on aws using gitlab ci

I created ressources on AWS using terraform and depolyed with gitlab ci. I want to send the output of the gitlab pipeline to a lambda function already existing but I have no idea if it's possible. br
0
votes
0 answers

Getting Error: [rast] cannot open file: Apr 2017_masked_idw2.asc when reading a list of rasters is terra package?

I have a montyly rasters containing 20 years. I want to read only rasters in the year 2017 as a list of files. But I am getting this error Error: [rast] cannot open file: Apr 2017_masked_idw2.asc In addition: Warning message: Apr…
Mukhtar Abdi
  • 391
  • 1
  • 12
0
votes
1 answer

Terra Spatial Correlation between two raster

I am trying to calculate the spatial correlation between two rasters. I have two large rasters with the same extent, resolution, etc class : RasterLayer dimensions : 45598, 53241, 2427683118 (nrow, ncol, ncell) resolution : 30, 30 (x,…
DarthOrion
  • 15
  • 4
0
votes
1 answer

Write RasterStack and preserve metadata in R

I would like to write a RasterStack object and preserve names and metadata of the individual layers. How to preserve names is explained here. Is there a way to preserve metadata of individual layers when writing a RasterStack object? Here is…
SophiaL
  • 61
  • 7
0
votes
2 answers

How to convert SpatVector column to datetime format in R?

I would like to convert a SpatVector column from character to POSIXct in R. Using as.POSIXct() doesn't throw an error or warning but the column is still character after. f <- system.file("ex/lux.shp", package="terra") v <- vect(f) v$DateTime <-…
ia200
  • 255
  • 1
  • 9
0
votes
1 answer

nrow limit when creating a raster using terra function rast

I'm trying to create a raster using the following data frame (without NAs), with the latitude, longitude and values extracted from a HDF4 file generated by SeaDAS: > dim(df) [1] 10538622 3 > head(df) x y z 1…