locationCreate: Connect to "GRASS"

.locationCreate,character-methodR Documentation

Connect to "GRASS"

Description

This function initializes a GRASS "project" (previously known in GRASS as a "location"; see vignette("projects_mapsets", package = "fasterRaster")). You need to run this function (often just once) before you use most functions in fasterRaster. This function is of use to developers, not most users.

Usage

## S4 method for signature 'character'
.locationCreate(x, location = NULL, overwrite = FALSE, warn = TRUE)

## S4 method for signature 'SpatRaster'
.locationCreate(x, location = NULL, overwrite = FALSE, warn = TRUE)

## S4 method for signature 'SpatVector'
.locationCreate(x, location = NULL, overwrite = FALSE, warn = TRUE)

## S4 method for signature 'sf'
.locationCreate(x, location = NULL, overwrite = FALSE, warn = TRUE)

Arguments

x

Any object from which a coordinate reference system (CRS) can be acquired. Ergo, any of:

  • A SpatRaster, SpatVector, SpatExtent, stars, or sf object

  • A crs object (i.e., from sf::st_crs()).

  • A CRS (coordinate reference system) WKT string. Some PROJ4 strings might work, too.

location

Character or NULL (default): Name of the location.

overwrite

Logical: If FALSE (default), and a GRASS "coordinate reference frame" with the given name has already been created, then the function will fail. If TRUE, then the existing GRASS "coordinate reference frame" of the same name will be overwritten. NOTE: This will not remove any R objects associated with rasters or vectors in the "location", but they will no longer work because the objects they point to will be overwritten.

warn

Logical: If TRUE (default) and overwrite is TRUE, then display a warning.

Value

A GLocation object (invisibly).

Examples

if (grassStarted()) {

# Setup
library(terra)

# Example data
madElev <- fastData("madElev")
madChelsa <- fastData("madChelsa")
madChelsa1 <- madChelsa[[1]]

# Convert SpatRasters to GRasters.
# Each raster has a different CRS so will be put into a different location.
elev <- fast(madElev)
chelsa1 <- fast(madChelsa1)

# Name of the currently active location
.location()
.location(elev)
.location(chelsa1)

# All available GRASS locations
.locations()

# Find location of an object among all active locations
.locationFind(elev)
.locationFind(chelsa1)
.locationFind(chelsa1, return = "index")
.locationFind(chelsa1, return = "crs")

# Switch between locations
.locationRestore(elev)
.locationRestore(chelsa1)

loc <- .location(elev)
.locationRestore(loc)

# We could use .locationDelete(elev) to delete
# the location where "elev" is stored.

# Mapsets are always "PERMANENT" in fasterRaster
.mapset()
.mapset(elev)
.mapset(chelsa1)

}

adamlilith/fasterRaster documentation built on Sept. 23, 2024, 1:28 a.m.