% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/00e_GVector_class.r
\name{makeGVector}
\alias{makeGVector}
\title{Create a GVector from a GRASS vector}
\usage{
makeGVector(
  src,
  table = NULL,
  build = TRUE,
  extensive = FALSE,
  cats = NULL,
  fail = TRUE
)
}
\arguments{
\item{src}{Character: The name of the vector in \strong{GRASS}.}

\item{table}{A \code{data.table}, \code{data.frame}, \code{GVector} with a table, or character. This can be \code{data.table(NULL)} or \code{data.frame(NULL)} if there is no table associated with the vector. If a character, this is interpreted as the name of the table in \strong{GRASS}.}

\item{build}{Logical: If \code{TRUE} (default), build topology using \strong{GRASS} tool \code{v.build}.}

\item{extensive}{Logical: If \code{TRUE}, do extensive topological checks using \code{v.build}. The default is \code{FALSE}.}

\item{cats}{\code{NULL} (default) or an integer vector: Values of the "cats" (categories) of the vector in \strong{GRASS}. This is useful \emph{only} for speeding up the \code{GVector} creation process when the "cats" have already been ascertained. For most users, this will be better left as \code{NULL}.}

\item{fail}{Logical: If \code{TRUE} (default), and the vector either has a 0 east-west or north-south extent, then exit the function with an error. If \code{fail} is \code{FALSE}, then display a warning and return \code{NULL}.}
}
\value{
A \code{GVector} (or \code{NULL} if \code{fail} is \code{TRUE} and the \code{GVector} would be invalid).
}
\description{
Create a \code{GVector} from a vector existing in the current \strong{GRASS} session.
}
\examples{
if (grassStarted()) {

# Setup
library(sf)
library(terra)

# Example data
madElev <- fastData("madElev") # integer raster
madCover <- fastData("madCover") # categorical raster
madCoast4 <- fastData("madCoast4") # polygons vector
madRivers <- fastData("madRivers") # lines vector
madDypsis <- fastData("madDypsis") # points vector

### Create GRasters from SpatRasters

# Create an integer raster:
elev <- fast(madElev)
elev

# Create a categorical raster:
cover <- fast(madCover)
madCover
levels(madCover) # category levels

# Create a GRaster from a file on disk:
rastFile <- system.file("extdata", "madForest2000.tif", package = "fasterRaster")
forest2000 <- fast(rastFile)
forest2000

# Create a 1's raster that spans the world:
ones <- fast(rastOrVect = "raster", crs = "epsg:4326")
ones

### Create GVectors

# Create a GVector from an sf vector:
coast4 <- fast(madCoast4)
coast4

# Create a GVector from a SpatVector:
madRivers <- vect(madRivers)
class(madRivers)
rivers <- fast(madRivers)
rivers

# Create a GVector from a vector on disk:
vectFile <- system.file("extdata/shapes", "madCoast.shp",
   package = "fasterRaster")
coast0 <- fast(vectFile)
coast0

# Import only Dypsis occurrences in a restricted area:
ant <- coast4[coast4$NAME_4 == "Antanambe"]
dypsisRestrict <- fast(madDypsis, extent = ant)
dypsis <- fast(madDypsis)

plot(coast4)
plot(ant, col = "gray80", add = TRUE)
plot(dypsis, add = TRUE)
plot(dypsisRestrict, col = "red", add = TRUE)

# Create a generic GVector that spans the world:
wallToWall <- fast(rastOrVect = "vector", crs = "epsg:4326") # WGS84
wallToWall

# Create a GVector from a numeric vector
pts <- c(-90.2, 38.6, -122.3, 37.9)
pts <- fast(pts, crs = "epsg:4326") # WGS84

# Create a GVector from a matrix (can also use data.frame or data.table):
mat <- matrix(c(-90.2, 38.6, -122.3, 37.9), ncol = 2, byrow = TRUE)
mat <- fast(mat, crs = "epsg:4326", keepgeom = TRUE) # WGS84

}
}
\seealso{
\code{\link[=makeGRaster]{makeGRaster()}}
}
