% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/qgis.R
\name{QgisProject}
\alias{QgisProject}
\title{Interface to the QGIS Project}
\description{
The \code{QgisProject} class provides an R6 interface to interact with the
currently active QGIS project. It allows reading project properties, listing
layers, and transferring spatial data between R and QGIS.
}
\details{
Please note that you should not instantiate this class manually using
\code{QgisProject$new()}. Instead, use the public wrapper function
\code{\link{qgis_project}()} to safely establish the connection.
}
\section{Active bindings}{
\if{html}{\out{<div class="r6-active-bindings">}}
\describe{
\item{\code{title}}{(character) The title of the QGIS project (read-only).}

\item{\code{path}}{(character) The absolute path to the QGIS project file (read-only).}

\item{\code{crs}}{(character) The authority ID of the project's CRS (e.g., "EPSG:4326") (read-only).}

\item{\code{units}}{(character) The map units of the project (e.g., "meters") (read-only).}
}
\if{html}{\out{</div>}}
}
\section{Methods}{
\subsection{Public methods}{
\itemize{
\item \href{#method-QgisProject-new}{\code{QgisProject$new()}}
\item \href{#method-QgisProject-list_layers}{\code{QgisProject$list_layers()}}
\item \href{#method-QgisProject-get_layer}{\code{QgisProject$get_layer()}}
\item \href{#method-QgisProject-insert_layer}{\code{QgisProject$insert_layer()}}
\item \href{#method-QgisProject-layer_info}{\code{QgisProject$layer_info()}}
\item \href{#method-QgisProject-get_canvas_extent}{\code{QgisProject$get_canvas_extent()}}
\item \href{#method-QgisProject-get_selected_features}{\code{QgisProject$get_selected_features()}}
\item \href{#method-QgisProject-print}{\code{QgisProject$print()}}
\item \href{#method-QgisProject-clone}{\code{QgisProject$clone()}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-QgisProject-new"></a>}}
\if{latex}{\out{\hypertarget{method-QgisProject-new}{}}}
\subsection{Method \code{new()}}{
Create a new \code{QgisProject} object.
This is typically instantiated via qgis_project().
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{QgisProject$new(data = NULL)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{data}}{A list containing the initial project state.
If \code{NULL}, it will be requested from QGIS. For internal use.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A new \code{QgisProject} object.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-QgisProject-list_layers"></a>}}
\if{latex}{\out{\hypertarget{method-QgisProject-list_layers}{}}}
\subsection{Method \code{list_layers()}}{
Lists layers available in the current QGIS project.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{QgisProject$list_layers(type = NULL)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{type}}{(integer) An optional filter for layer type.
Corresponds to \code{QgsMapLayerType}: \code{0} for vector, \code{1} for raster.
Use \code{NULL} to list all layers.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A data frame with the \code{name} and \code{id} of the layers.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-QgisProject-get_layer"></a>}}
\if{latex}{\out{\hypertarget{method-QgisProject-get_layer}{}}}
\subsection{Method \code{get_layer()}}{
Reads a QGIS layer and loads it into R as a spatial object.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{QgisProject$get_layer(x, ...)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{x}}{(character) The name or ID of the layer to get.}

\item{\code{...}}{Additional arguments passed to \code{sf::st_read()} for vector
layers.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
An \code{sf} object for vector layers or a \code{SpatRaster} object
from the \code{terra} package for raster layers.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-QgisProject-insert_layer"></a>}}
\if{latex}{\out{\hypertarget{method-QgisProject-insert_layer}{}}}
\subsection{Method \code{insert_layer()}}{
Inserts an R spatial object into the QGIS project as a new layer.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{QgisProject$insert_layer(layer, name = NULL, ...)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{layer}}{The spatial object to insert. Must be an \code{sf} object or
a \code{SpatRaster} from the \code{terra} package.}

\item{\code{name}}{(character) The desired name for the new layer in QGIS.
If \code{NULL}, a name will be generated from the object's variable name.}

\item{\code{...}}{Additional arguments passed to \code{sf::st_write()} for vector
layers.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
The \code{QgisProject} object, invisibly.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-QgisProject-layer_info"></a>}}
\if{latex}{\out{\hypertarget{method-QgisProject-layer_info}{}}}
\subsection{Method \code{layer_info()}}{
Prints detailed information about a specific layer.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{QgisProject$layer_info(x)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{x}}{(character) The name or ID of the layer.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
The \code{QgisProject} object, invisibly.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-QgisProject-get_canvas_extent"></a>}}
\if{latex}{\out{\hypertarget{method-QgisProject-get_canvas_extent}{}}}
\subsection{Method \code{get_canvas_extent()}}{
Gets the extent of the current map canvas.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{QgisProject$get_canvas_extent()}\if{html}{\out{</div>}}
}

\subsection{Returns}{
A \code{bbox} object from the \code{sf} package representing the
current view extent.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-QgisProject-get_selected_features"></a>}}
\if{latex}{\out{\hypertarget{method-QgisProject-get_selected_features}{}}}
\subsection{Method \code{get_selected_features()}}{
Gets the selected features from the currently active vector layer in QGIS.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{QgisProject$get_selected_features()}\if{html}{\out{</div>}}
}

\subsection{Returns}{
An \code{sf} object containing the selected features.
Returns an error if the active layer is not a vector layer or has no
selection.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-QgisProject-print"></a>}}
\if{latex}{\out{\hypertarget{method-QgisProject-print}{}}}
\subsection{Method \code{print()}}{
Prints a summary of the QGIS project information.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{QgisProject$print(...)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{...}}{Ignored.}
}
\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-QgisProject-clone"></a>}}
\if{latex}{\out{\hypertarget{method-QgisProject-clone}{}}}
\subsection{Method \code{clone()}}{
The objects of this class are cloneable with this method.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{QgisProject$clone(deep = FALSE)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{deep}}{Whether to make a deep clone.}
}
\if{html}{\out{</div>}}
}
}
}
