| rpygeo_load {RPyGeo} | R Documentation |
Load output of ArcPy functions into R session
Description
This function loads the output of an ArcPy function into the R session. Raster files are loaded as raster objects and vector files as sf objects.
Usage
rpygeo_load(data)
Arguments
data |
|
Details
Currently files and datasets stored in file geodatabases are supported.
Supported file formats:
Tagged Image File Format (.tif)
Erdas Imagine Images (.img)
Esri Arc/Info Binary Grid (.adf)
Esri ASCII Raster (.asc)
Esri Shapefiles (.shp)
Supported datasets:
Feature Class
Raster Dataset
Esri has not released an API for raster datasets in file geodatabases. rpygeo_load converts a raster dataset to a temporary ASCII raster first and then loads it into the R session. Be aware that this can take a long time for large raster datasets.
This function can be used with the %>% operator from the dplyr package. The %>% operator forwards the reticulate object from the ArcPy function to rpygeo_load (s. Example 1). If used without the %>% operator an reticulate object can be specified for the data parameter (s. Example 2). It is also possible to use the filename of the ArcPy function output (s. Example 3). For Arc/Info Binary Grids the data parameter is just the name of the directory, which contains the adf files.
Value
raster or sf object
Author(s)
Marc Becker
Examples
## Not run:
# Load packages
library(RPyGeo)
library(magrittr)
library(RQGIS)
library(spData)
# Get data
data(dem, package = "RQGIS")
data(nz, package = "spData")
# Write data to disk
writeRaster(dem, file.path(tempdir(), "dem.tif"), format = "GTiff")
st_write(nz, file.path(tempdir(), "nz.shp"))
# Load the ArcPy module and build environment
arcpy <- arcpy_build_env(overwrite = TRUE, workspace = tempdir())
# Create a slope raster and load it into the R session (Example 1)
slope <-
arcpy$Slope_3d(in_raster = "dem.tif", out_raster = "slope.tif") %>%
rpygeo_load()
# Create a aspect raster and load it into the R session (Example 2)
ras_aspect <- arcpy$sa$Aspect(in_raster = "dem.tif")
rpygeo_load(ras_aspect)
# Convert elevation raster to polygon shapefile and load it into R session (Example 3)
arcpy$RasterToPolygon_conversion("dem.tif", "elev.shp")
rpygeo_load("elev.shp")
## End(Not run)