Examples for 'terra::values<-'


Set the values of raster cells or of geometry attributes

Aliases: values<- values<-,SpatRaster,ANY-method setValues setValues,SpatRaster-method setValues,SpatRaster,ANY-method values<-,SpatVector,data.frame-method values<-,SpatVector,matrix-method values<-,SpatVector,ANY-method values<-,SpatVector,NULL-method setValues,SpatVector-method setValues,SpatVector,ANY-method

Keywords: spatial methods

### ** Examples

f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
x <- setValues(r, 1:ncell(r))
x
class       : SpatRaster 
dimensions  : 90, 95, 1  (nrow, ncol, nlyr)
resolution  : 0.008333333, 0.008333333  (x, y)
extent      : 5.741667, 6.533333, 49.44167, 50.19167  (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 (EPSG:4326) 
source      : memory 
name        : elevation 
min value   :         1 
max value   :      8550 
values(x) <- runif(ncell(x))
x
class       : SpatRaster 
dimensions  : 90, 95, 1  (nrow, ncol, nlyr)
resolution  : 0.008333333, 0.008333333  (x, y)
extent      : 5.741667, 6.533333, 49.44167, 50.19167  (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 (EPSG:4326) 
source      : memory 
name        :    elevation 
min value   : 5.562371e-05 
max value   :    0.9999671 
head(x)
  elevation
1 0.9070698
2 0.5131698
3 0.6891025
4 0.5113533
5 0.2971274
6 0.3495276
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
values(v) <- data.frame(ID=1:12, name=letters[1:12])
head(v)
  ID name
1  1    a
2  2    b
3  3    c
4  4    d
5  5    e
6  6    f

[Package terra version 1.5-34 Index]