% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/grid_io.R
\name{maxent_grid_to_terra}
\alias{maxent_grid_to_terra}
\title{Convert a maxentcpp GridFloat to a terra SpatRaster}
\usage{
maxent_grid_to_terra(grid, crs = "EPSG:4326")
}
\arguments{
\item{grid}{External pointer to a GridFloat C++ object.}

\item{crs}{Character: coordinate reference system string
(default \code{"EPSG:4326"}, i.e. WGS 84 longitude/latitude).}
}
\value{
A single-layer \code{terra::SpatRaster}.
}
\description{
Creates a \code{terra::SpatRaster} from a maxentcpp GridFloat external
pointer.
}
\details{
Requires the \pkg{terra} package (listed in Suggests).

For the \pkg{raster} package, an equivalent workflow is:
\preformatted{
  library(raster)
  info <- maxent_grid_info(grid)
  mat  <- maxent_grid_to_matrix(grid)
  r <- raster(mat,
              xmn = info$xll,
              xmx = info$xll + info$ncols * info$cellsize,
              ymn = info$yll,
              ymx = info$yll + info$nrows * info$cellsize,
              crs = "+proj=longlat +datum=WGS84")
}
}
\examples{
\donttest{
stack_path <- system.file("extdata", "stack_1_12_crop.rds",
                         package = "maxentcpp")
r <- terra::unwrap(readRDS(stack_path))
g <- maxent_grid_from_terra(r[[1]])
r2 <- maxent_grid_to_terra(g)
}
}
