实验目的:

学习R包的信息查看和R包自带案例的使用方法,以terra包为例。

实验步骤:

1.安装terra包

在R中执行如下命令:

install.packages("terra")

2.查看包信息

在R中执行如下命令:

library(terra)
packageDescription("terra")

执行结果如下:

Package: terra
Type: Package
Title: Spatial Data Analysis
Version: 1.5-9
Date: 2021-10-27
Author: Robert J. Hijmans [aut, cre], Edzer Pebesma [ctb], Chris Brunsdon [ctb], Roger Bivand [ctb], Michael Sumner [ctb], Matteo Mattiuzzi [ctb], John Paul Cañas [ctb], Hao Zhang [ctb], Dan Baston [ctb], Steven Mosher [ctb], Kevin Coombs [ctb], Loic Dutrieux [ctb], Forrest Stevens [ctb], Chris Funk [ctb], Patrick Brown [ctb], Belen Gallego-Elvira [ctb], Nick Matzke [ctb], Sean Laidlaw [ctb], Jonathan A. Greenberg [ctb], Josh Gray [ctb], Tomislav Hengl [ctb], Aaron Olsen [ctb], Kelly Hondula [ctb], Andrew Bevan [ctb], Daniel Schlaepfer [ctb], Robert Zinke [ctb], Andrew Parnell [ctb], Steven Phillips [ctb], Julian M. Burgos [ctb], Daniel Nusbaum [ctb], Niklaus Zimmermann [ctb], Drew Tyre [ctb], David Bucklin [ctb], Tim Appelhans [ctb], Guillaume Blanchet [ctb], Philippe Grondin [ctb], James Regetz [ctb], Florian Detsch [ctb], Andrew Nelson [ctb], Bjorn Reu [ctb], Matteo De Felice [ctb], Matteo Mattiuzzi [ctb], Brian O'Meara [ctb], Mark Padgham [ctb], Francois Gillet [ctb], Marco Sciaini [ctb], Blair Skillman [ctb], Mark Ward [ctb], Dan Tenenbaum [ctb], Daniel Schlaepfer [ctb], Dan Baston [ctb], Pedro J. Aphalo [ctb]
Maintainer: Robert J. Hijmans <r.hijmans@gmail.com>
Description: Methods for spatial data analysis. It includes (among others) operators for algebraic, geometric, and relational operations on vector and raster data, reading and writing vector and raster data in many formats, and a variety of methods for spatial data manipulation. It also includes methods for raster image processing and for solving common problems in spatial data analysis using distance matrices, spatial weights matrices, and kriging. Terra is the successor to the 'raster' package.
License: GPL (>= 3)
LazyLoad: yes
LazyData: yes
Suggests: knitr, rmarkdown, testthat, covr, microbenchmark, magrittr, ggplot2, sp, rgdal, rgeos, raster, sf, maptools, classInt, gstat, NCmisc, scales
Imports: Rcpp (>= 1.0.7), methods, stats, utils, grDevices
LinkingTo: Rcpp, RcppArmadillo
SystemRequirements: C++11
NeedsCompilation: yes
Packaged: 2021-10-28 00:15:51 UTC; rhijmans
Repository: CRAN
Date/Publication: 2021-10-28 17:30:03 UTC

可以看到terra包的作者、版本、描述、许可证等信息。

3.查看包帮助文档

在R中执行如下命令:

help("terra")

将会打开terra包的帮助文档。

4.使用包自带案例

在R中执行如下命令:

demo(terra)

将会打开terra包的自带案例。

执行结果如下:

> demo(terra)

		demo(terra)
		--------------
		terra version 1.5-9 (2021)
		See 'terra-vignette' for an overview and examples.
		
		For questions or comments use https://community.rstudio.com/ or
		the 'terra' or 'raster' tags on https://stackoverflow.com/
		
		Terra is based on the 'raster' package, developed by Robert J. Hijmans, Jacob van Etten, and others. 
		Terra is faster and more memory efficient than raster, and has many new features. 
		It can read and write raster files in many formats, and can be used to manipulate vector data. 
		It is suitable for large datasets and is particularly good for processing time series of satellite imagery. 
		The terra package is mainly developed by Robert J. Hijmans, with contributions from many others.
		
		> r <- rast(system.file("ex/elev.tif", package="terra"))
		
		# basic functions
		plot(r)
		plot(r, col=terrain.colors(255))
		as.data.frame(r)
		summary(r)
		
		# algebra
		r + 100
		r - 100
		r * 2
		r / 2
		r ^ 2
		log(r)
		exp(r)
		sin(r)
		cos(r)
		tan(r)
		atan(r)
		atan2(r, 5)
		
		# statistics
		cellStats(r, sum)
		cellStats(r, mean)
		cellStats(r, min)
		cellStats(r, max)
		cellStats(r, sd)
		cellStats(r, var)
		cellStats(r, quantile, probs=0.10)
		
		# reclassification
		rc <- c(-Inf, 0, 100, Inf)
		r2 <- reclass(r, rc)
		plot(r2)
		
		# focal operations
		f <- focal(r, w=matrix(1, 3, 3))
		plot(f)
		f2 <- focalWeight(r, w=matrix(1, 3, 3), fun=sum)
		plot(f2)
		
		# resampling
		r3 <- resample(r, 1000, method="bilinear")
		plot(r3)
		
		# aggregation
		r4 <- aggregate(r, fact=10, fun=mean)
		plot(r4)
		
		# buffer
		p <- vect(system.file("ex/lux.shp", package="terra"))
		b <- buffer(p, 1000)
		plot(b)

可以看到,案例中演示了terra包的基本使用方法,包括读取和处理栅格数据、栅格代数运算、栅格统计、重分类、邻域操作、重采样、聚合和缓冲区等操作。

实验结论:

通过本次实验,学习了如何查看R包的信息和使用R包自带案例,以terra包为例。掌握了R包的基本信息查看方法和R包自带案例的使用方法,学习了terra包的基本使用方法,包括读取和处理栅格数据、栅格代数运算、栅格统计、重分类、邻域操作、重采样、聚合和缓冲区等操作

学会查看R包的信息 并学会使用R包自带案例 以terra包为例 请提交实验报告

原文地址: https://www.cveoy.top/t/topic/fr6M 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录