locationRestore: Revert to a previously-created "GRASS" "location"

.locationRestore,character-methodR Documentation

Revert to a previously-created "GRASS" "location"

Description

This function resets the connection to a previously-created GRASS "location". The session must have been already created using fast() in the current R session. This function is typically only of use to developers.

Usage

## S4 method for signature 'character'
.locationRestore(x)

## S4 method for signature 'integer'
.locationRestore(x)

## S4 method for signature 'numeric'
.locationRestore(x)

## S4 method for signature 'GSpatial'
.locationRestore(x)

Arguments

x

Either:

  • A character: Name of the "location" in GRASS.

  • An integer: Index of the "location" in .fasterRaster$locations.

  • A GSpatial object (usually a GRaster or GVector).

Any of these can be found using .locationFind().

Value

An object of class GLocation (invisibly) if successful. An error will likely result if not.

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
if (FALSE) {
   
   .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)

   # Delete the location where "elev" is stored.
   if (FALSE) .locationDelete(elev) # dangerous!

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

}

}

adamlilith/fasterRaster documentation built on Oct. 26, 2024, 4:06 p.m.