locationFind: Match CRS of a GSpatial object and an existing "GRASS"...

.locationFind,missing-methodR Documentation

Match CRS of a GSpatial object and an existing "GRASS" location

Description

The function searches the set of available GRASS "projects" (previously known as "locations") for one that has a coordinate reference system matching a GSpatial object. If none are found, or if no connection with GRASS has yet been made, then it returns NULL. Otherwise, it returns either the index or the name of the matching location.

Usage

## S4 method for signature 'missing'
.locationFind(x, return = "name")

## S4 method for signature 'GLocation'
.locationFind(x, return = "name", match = "name")

## S4 method for signature 'SpatRaster'
.locationFind(x, return = "name", match = "name")

## S4 method for signature 'SpatVector'
.locationFind(x, return = "name", match = "name")

## S4 method for signature 'sf'
.locationFind(x, return = "name", match = "name")

## S4 method for signature 'character'
.locationFind(x, return = "name", match = "name")

Arguments

x

Either:

  • Missing: Returns names and coordinate reference system strings of all "locations".

  • A character representing a coordinate reference system in WKT format

  • A SpatRaster, SpatVector, or sf vector with a coordinate reference system

  • A GSpatial object (usually a GRaster or GVector)

return

Either:

  • "name" (default): Returns the name of the "location" with a coordinate reference system the same as x.

  • "index": Returns the index of this "location" in .fasterRaster$locations of the .fasterRaster environment.

  • "crs": Returns the coordinate reference system of this "project/location".

match

Character: Method used to find the location. If match is "name"" (default), then the name of the location is used. If match is "crs", then the coordinate reference system of each location is checked for a match.

Value

Character, integer, or NULL (if no match is found).

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.