% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/crs.r
\name{crs,missing-method}
\alias{crs,missing-method}
\alias{crs}
\alias{crs,GLocation-method}
\alias{st_crs,missing-method}
\alias{st_crs}
\alias{st_crs,GLocation-method}
\alias{coordRef,missing-method}
\alias{coordRef}
\alias{coordRef,GRaster-method}
\alias{coordRef,GVector-method}
\title{Coordinate reference system of a GRaster or GVector}
\usage{
\S4method{crs}{missing}(x)

\S4method{crs}{GLocation}(x)

\S4method{st_crs}{missing}(x, ...)

\S4method{st_crs}{GLocation}(x, ...)

st_crs(x, ...)

\S4method{coordRef}{missing}(x)

\S4method{coordRef}{GRaster}(x)

\S4method{coordRef}{GVector}(x)
}
\arguments{
\item{x}{An object that inherits from a \code{GLocation} (i.e., a \code{GRaster} or \code{GVector}) or missing. If missing, the coordinate reference system of the currently active \strong{GRASS} "project/location" is reported.}

\item{...}{Other arguments (generally unused).}
}
\value{
Function \code{crs()} returns a \code{character} object, \code{st_crs()} returns \code{crs} object, and \code{coordRef()} a \code{list}.
}
\description{
Get the coordinate reference system (CRS) of a \code{GRaster} or \code{GVector}s, or from the currently active \strong{GRASS} "project/location" (see \code{vignette("projects_mapsets", package = "fasterRaster")}):
\itemize{
\item \code{crs()}: Return a WKT string (an object of class \code{character}).
\item \code{st_crs()}: Return a \code{crs} object (from the \strong{sf} package).
\item \code{coordRef()}: Return a \code{list}.
}
}
\examples{
if (grassStarted()) {

# Setup
library(terra)

# Example data
madElev <- fastData("madElev")
madForest2000 <- fastData("madForest2000")

# Convert SpatRasters to GRasters
elev <- fast(madElev)
forest <- fast(madForest2000)

### GRaster properties

# plotting
plot(elev)

# dimensions
dim(elev) # rows, columns, depths, layers
nrow(elev) # rows
ncol(elev) # columns
ndepth(elev) # depths
nlyr(elev) # layers

res(elev) # resolution (2D)
res3d(elev) # resolution (3D)
zres(elev) # vertical resolution
xres(elev) # vertical resolution
yres(elev) # vertical resolution
zres(elev) # vertical resolution (NA because this is a 2D GRaster)

# cell counts
ncell(elev) # cells
ncell3d(elev) # cells (3D rasters only)

# number of NA and non-NA cells
nacell(elev)
nonnacell(elev)

# topology
topology(elev) # number of dimensions
is.2d(elev) # is it 2-dimensional?
is.3d(elev) # is it 3-dimensional?

minmax(elev) # min/max values

# "names" of the object
names(elev)

# coordinate reference system
crs(elev)
st_crs(elev)
coordRef(elev)

# extent (bounding box)
ext(elev)

# vertical extent (not defined for this raster)
zext(elev)

# data type
datatype(elev) # fasterRaster type
datatype(elev, "GRASS") # GRASS type
datatype(elev, "terra") # terra type
datatype(elev, "GDAL") # GDAL type

is.integer(elev)
is.float(elev)
is.double(elev)
is.factor(elev)

# convert data type
as.int(elev) # integer; note that "elev" is already of type "integer"
as.float(elev) # floating-precision
as.doub(elev) # double-precision

# assigning
pie <- elev
pie[] <- pi # assign all cells to the value of pi
pie

# concatenating multiple GRasters
rasts <- c(elev, forest)
rasts

# subsetting
rasts[[1]]
rasts[["madForest2000"]]

# replacing
rasts[[2]] <- 2 * forest
rasts

# adding layers
rasts[[3]] <- elev > 500 # add a layer
rasts <- c(rasts, sqrt(elev)) # add another
add(rasts) <- ln(elev)
rasts

# names
names(rasts)
names(rasts) <- c("elev_meters", "2_x_forest", "high_elevation", "sqrt_elev", "ln_elev")
rasts

# remove a layer
rasts[["2_x_forest"]] <- NULL
rasts

# number of layers
nlyr(rasts)

# correlation and covariance matrices
madLANDSAT <- fastData("madLANDSAT")
landsat <- fast(madLANDSAT) # projects matrix
layerCor(landsat) # correlation
layerCor(landsat, fun = 'cov') # covariance

}
}
\seealso{
\code{\link[terra:crs]{terra::crs()}}, \code{\link[sf:st_crs]{sf::st_crs()}}
}
