我正在使用极地北极植被地图。存储为带有 terra 的 SpatRaster,该栅格具有 21 个土地覆盖类别。
> str(lc_2003)
Formal class 'SpatRaster' [package "terra"] with 1 slot
..@ ptr:Reference class 'Rcpp_SpatRaster' [package "terra"] with 17 fields
.. ..$ depth : num 0
.. ..$ extent :Reference class 'Rcpp_SpatExtent' [package "terra"] with 2 fields
.. .. ..$ valid : logi TRUE
.. .. ..$ vector: num [1:4] 3946387 7965081 2200504 5681579
.. .. ..and 27 methods, of which 13 are possibly relevant:
.. .. .. align, as.points, ceil, compare, finalize, floor, initialize, intersect, round, sample,
.. .. .. sampleRandom, sampleRegular, union
.. ..$ filenames: chr ""
.. ..$ hasRange : logi TRUE
.. ..$ hasTime : logi FALSE
.. ..$ hasValues: logi TRUE
.. ..$ inMemory : logi TRUE
.. ..$ messages :Reference class 'Rcpp_SpatMessages' [package "terra"] with 2 fields
.. .. ..$ has_error : logi FALSE
.. .. ..$ has_warning: logi FALSE
.. .. ..and 18 methods, of which 4 are possibly relevant:
.. .. .. finalize, getError, getWarnings, initialize
.. ..$ names : chr "PHYSIOG"
.. ..$ origin : num [1:2] 102.7 91.3
.. ..$ range_max: num 21
.. ..$ range_min: num 1
.. ..$ res : num [1:2] 5172 3881
.. ..$ rgb : logi FALSE
.. ..$ time : num 0
.. ..$ timestep : chr "seconds"
.. ..$ units : chr ""
但是,我想将 PHYSIOG 层中的每个值与其实际的土地覆盖类名称相关联。这对我在 ArcGis 中查看文件以及评估某些调查地块属于哪种栖息地类型很有用。
landcover_classes <- data.frame(lc_code = 1:21,
lc_class = c(
"Cryptogam, herb barren",
"Rush/grass, forb, cryptogam tundra",
"Cryptogam barren complex (bedrock)",
"Prostrate dwarf-shrub, herb tundra",
"Graminoid, prostrate dwarf-shrub, forb tundra",
"Prostrate/Hemiprostrate dwarf-shrub tundra",
"Nontussock sedge, dwarf-shrub, moss tundra",
"Tussock-sedge, dwarf-shrub, moss tundra",
"Erect dwarf-shrub tundra",
"Low-shrub tundra",
"Missing (Cryprogram dwarf-shrub?)",
"Sedge/grass, moss wetland",
"Sedge, moss, dwarf-shrub wetland",
"Sedge, moss, low-shrub wetland",
"Noncarbonate mountain complex",
"Carbonate mountain complex",
"Nunatak complex",
"Glaciers",
"Water",
"Lagoon",
"Non-Arctic areas"))
如何将此数据添加到 SpatRaster?
(我不确定如何制作一个可重现的 SpatRaster 示例。我将在一个单独的问题中提出这个问题)