Title: | Interface to 'ArcGIS' 'Python' Modules |
---|---|
Description: | An interface to the 'ArcGIS' 'arcpy' and 'arcgis' 'python' API <https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/arcgis-api-for-python.htm>. Provides various tools for installing and configuring a 'Conda' environment for accessing 'ArcGIS' geoprocessing functions. Helper functions for manipulating and converting 'ArcGIS' objects from R are also provided. |
Authors: | Michael Koohafkan [aut, cre] |
Maintainer: | Michael Koohafkan <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.4-0 |
Built: | 2025-01-01 04:36:47 UTC |
Source: | https://github.com/mkoohafkan/arcpy |
An interface to the ArcGIS arcpy
Python module via the
R-Python interface provided by reticulate
. Loading the
packages exposes the arcpy
and arcgis
python modules for
accessing the ArcGIS geoprocessor.
See the vignettes to get started.
Maintainer: Michael Koohafkan [email protected]
Verify the supplied arcpy module version and identify the required Python version.
arcpy_version(version, conda = "auto", channel = "esri", forge = TRUE)
arcpy_version(version, conda = "auto", channel = "esri", forge = TRUE)
version |
The arcpy module version. |
conda |
The path to a |
channel |
An optional character vector of conda channels to include.
When specified, the |
forge |
Boolean; include the conda-forge repository? |
A named list providing version numbers of arcpy and Python.
Drop records from a table (e.g. attribute table of a layer) with the arcpy.da module.
da_drop(table.path, rows)
da_drop(table.path, rows)
table.path |
The file path to the table. |
rows |
The row indexes to drop. |
(Invisible) The path to the table, i.e. table.path
.
## Not run: arcpy$env$workspace = tempdir() arcpy$env$scratchWorkspace = tempdir() fc = arcpy$management$CopyFeatures(system.file("CA_Counties", "CA_Counties_TIGER2016.shp", package = "arcpy"), "CA_Counties") d = da_read(fc, c("STATEFP", "COUNTYFP")) drop.rows = which(d$STATEFP == "06" & d$COUNTYFP == "067") da_drop(fc, drop.rows) ## End(Not run)
## Not run: arcpy$env$workspace = tempdir() arcpy$env$scratchWorkspace = tempdir() fc = arcpy$management$CopyFeatures(system.file("CA_Counties", "CA_Counties_TIGER2016.shp", package = "arcpy"), "CA_Counties") d = da_read(fc, c("STATEFP", "COUNTYFP")) drop.rows = which(d$STATEFP == "06" & d$COUNTYFP == "067") da_drop(fc, drop.rows) ## End(Not run)
Read attribute table field names with 'arcpy.da“ module.
da_fields(table.path)
da_fields(table.path)
table.path |
The file path to the table. |
A vector of field names.
## Not run: arcpy$env$workspace = tempdir() arcpy$env$scratchWorkspace = tempdir() fc = arcpy$management$CopyFeatures(system.file("CA_Counties", "CA_Counties_TIGER2016.shp", package = "arcpy"), "CA_Counties") da_fields(fc) ## End(Not run)
## Not run: arcpy$env$workspace = tempdir() arcpy$env$scratchWorkspace = tempdir() fc = arcpy$management$CopyFeatures(system.file("CA_Counties", "CA_Counties_TIGER2016.shp", package = "arcpy"), "CA_Counties") da_fields(fc) ## End(Not run)
Insert records into a table (e.g. attribute table of a layer) with the arcpy.da module.
da_insert(table.path, d)
da_insert(table.path, d)
table.path |
The file path to the table. |
d |
The data to write to |
(Invisible) The path to the table, i.e. table.path
.
## Not run: arcpy$env$workspace = tempdir() arcpy$env$scratchWorkspace = tempdir() fc = arcpy$management$CopyFeatures(system.file("CA_Counties", "CA_Counties_TIGER2016.shp", package = "arcpy"), "CA_Counties") d = da_read(fc, c("ALAND", "CLASSFP")) add.d = data.frame(ALAND= 1e4, CLASSFP = "H2", stringsAsFactors = FALSE) da_insert(fc, add.d) ## End(Not run)
## Not run: arcpy$env$workspace = tempdir() arcpy$env$scratchWorkspace = tempdir() fc = arcpy$management$CopyFeatures(system.file("CA_Counties", "CA_Counties_TIGER2016.shp", package = "arcpy"), "CA_Counties") d = da_read(fc, c("ALAND", "CLASSFP")) add.d = data.frame(ALAND= 1e4, CLASSFP = "H2", stringsAsFactors = FALSE) da_insert(fc, add.d) ## End(Not run)
Read a table (e.g. attribute table of a layer) with the
arcpy.da
module.
da_read(table.path, fields, simplify = TRUE)
da_read(table.path, fields, simplify = TRUE)
table.path |
The file path to the table. |
fields |
A vector of field names or column indices to retrieve. |
simplify |
If |
This implementation may be faster than accessing the
@data
slot of an object created from rgdal::readOGR
in cases where there are a very large number of features. An
additional advantage of da_read
is that it can read
raster attribute tables and stand-alone tables stored in file
geodatabases, which is not supported by rgdal::readOGR
.
a dataframe with columns corresponding to fields
.
## Not run: arcpy$env$workspace = tempdir() arcpy$env$scratchWorkspace = tempdir() fc = arcpy$management$CopyFeatures(system.file("CA_Counties", "CA_Counties_TIGER2016.shp", package = "arcpy"), "CA_Counties") da_read(fc, c("COUNTYFP", "ALAND")) ## End(Not run)
## Not run: arcpy$env$workspace = tempdir() arcpy$env$scratchWorkspace = tempdir() fc = arcpy$management$CopyFeatures(system.file("CA_Counties", "CA_Counties_TIGER2016.shp", package = "arcpy"), "CA_Counties") da_read(fc, c("COUNTYFP", "ALAND")) ## End(Not run)
Update a table (e.g., attribute table of a layer) with the arcpy.da module.
da_update(table.path, d)
da_update(table.path, d)
table.path |
The file path to the table. |
d |
The data to write to |
(Invisible) The path to the table, i.e. table.path
.
## Not run: arcpy$env$workspace = tempdir() arcpy$env$scratchWorkspace = tempdir() fc = arcpy$management$CopyFeatures(system.file("CA_Counties", "CA_Counties_TIGER2016.shp", package = "arcpy"), "CA_Counties") d = da_read(fc, "ALAND") d["ALAND"] = d$ALAND+ 5000 da_update(fc, d) ## End(Not run)
## Not run: arcpy$env$workspace = tempdir() arcpy$env$scratchWorkspace = tempdir() fc = arcpy$management$CopyFeatures(system.file("CA_Counties", "CA_Counties_TIGER2016.shp", package = "arcpy"), "CA_Counties") d = da_read(fc, "ALAND") d["ALAND"] = d$ALAND+ 5000 da_update(fc, d) ## End(Not run)
Create a Conda environment with the "arcpy" module.
install_arcpy( method = "conda", conda = "auto", version = NULL, envname = "r-arcpy", extra_packages = NULL, restart_session = TRUE, python_version = NULL, channel = "esri", forge = TRUE, ..., new_env = identical(envname, "r-arcpy") )
install_arcpy( method = "conda", conda = "auto", version = NULL, envname = "r-arcpy", extra_packages = NULL, restart_session = TRUE, python_version = NULL, channel = "esri", forge = TRUE, ..., new_env = identical(envname, "r-arcpy") )
method |
Installation method. By default, "auto" automatically finds a method that will work in the local environment. Change the default to force a specific installation method. Note that the "virtualenv" method is not available on Windows. |
conda |
The path to a |
version |
Arcpy version to install. Note that the requested arcpy version must match your ArcGIS Pro version. |
envname |
The name, or full path, of the environment in which Python
packages are to be installed. When |
extra_packages |
Additional Python packages to install along with arcpy. |
restart_session |
Restart R session after installing (note this will only occur within RStudio). |
python_version |
Pass a string like "3.9" to request that
conda install a specific Python version. Note that the Python
version must be compatible with the requested arcpy version. If
|
channel |
An optional character vector of conda channels to include.
When specified, the |
forge |
Boolean; include the conda-forge repository? |
... |
other arguments passed to |
new_env |
If |
The Conda environment must be configured to match the ArcGIS Pro version currently installed. If ArcGIS Pro is updated, the Conda environment must be recreated.
(Invisible) TRUE
if the Conda environment was created
successfully.
Convert rasters and features between R and ArcGIS.
to_arcpy(x, ...) from_arcpy(x, ...)
to_arcpy(x, ...) from_arcpy(x, ...)
x |
A raster or feature. |
... |
Reservered for future expansion. |
For to_arcpy()
, an ArcGIS raster or feature layer.
For from_arcpy()
, a SpatRaster
or sf
object.