{"id":28534720,"url":"https://github.com/r-spatial/rpygeo","last_synced_at":"2026-03-11T19:31:23.987Z","repository":{"id":56937107,"uuid":"94976100","full_name":"r-spatial/RPyGeo","owner":"r-spatial","description":"Update of RPyGeo package - currently WIP ","archived":false,"fork":false,"pushed_at":"2020-04-05T08:22:49.000Z","size":497,"stargazers_count":30,"open_issues_count":4,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-09T11:54:51.814Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/r-spatial.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-21T07:30:55.000Z","updated_at":"2025-04-21T12:27:00.000Z","dependencies_parsed_at":"2022-08-21T05:50:50.502Z","dependency_job_id":null,"html_url":"https://github.com/r-spatial/RPyGeo","commit_stats":null,"previous_names":["fapola/rpygeo"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/r-spatial/RPyGeo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-spatial%2FRPyGeo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-spatial%2FRPyGeo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-spatial%2FRPyGeo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-spatial%2FRPyGeo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r-spatial","download_url":"https://codeload.github.com/r-spatial/RPyGeo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-spatial%2FRPyGeo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265322661,"owners_count":23746670,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-09T17:12:29.780Z","updated_at":"2025-12-12T02:25:11.668Z","avatar_url":"https://github.com/r-spatial.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntitle: \"RPyGeo\"\noutput: github_document\n---\n\n```{r setup, include=FALSE}\nknitr::opts_chunk$set(echo = TRUE)\n```\n\n## Status\n\n\u003c!-- badges: start --\u003e\n[![Lifecycle: retired](https://img.shields.io/badge/lifecycle-dormant-blue.svg)](https://www.tidyverse.org/lifecycle/#dormant)\n\u003c!-- badges: end --\u003e\n\nRPyGeo is no longer under active development and no support is available. \n\n## Introduction\n\n**RPyGeo** establishes an interface to the geoprocessing tools of ArcGIS from within R.\nSince ArcGIS only provides a Python API for a low-level access of its C++ based geoalgorithms, **RPyGeo** establishes a tunnel to Python via the **reticulate** package.\nThis extends R's spatial capabilities (Bivand, Pebesma, \u0026 Gómez-Rubio, 2013; Hijmans, 2017) by the geoalgorithms and the geoprocessing power of ArcGIS.\nCombining this with the statistical and data science power of R opens the way to advanced console-base statistical geoprocessing (Muenchow, Schratz, \u0026 Brenning, 2017). \n\nTo use **RPyGeo** properly, at least a basic understanding of **ArcPy** is necessary.\nArcPy is a Python side-package that allows geographic data analysis through ArcGIS from the Python command line.\nArcPy is organized into modules which are Python files with functions and classes. The ArcPy main module `arcpy` (or `arcgis` module in ArcGIS API for Python) provides (geographic) classes and several hundred functions.\nFurther modules (e.g., `data access`) and extensions (e.g., `spatial analysis`) further extend the ArcPy main module.\nWe do recommend to get familiar with ArcPy through the official [help pages](https://pro.arcgis.com/en/pro-app/arcpy/main/arcgis-pro-arcpy-reference.htm). \nThere also several books available on ArcGIS and ArcPy such as \nZandbergen (2013) and Pimpler (2015).\n\n## Installation\n\nYou can get the latest RPyGeo version with dependencies from Github:\n\n```{r, eval = FALSE}\ndevtools::install_github(\"r-spatial/RPyGeo\", dependencies = TRUE, force = TRUE)\n```\n\nIn order to use RPyGeo you need to install ArcMap or ArcGIS Pro. ArcPy is included in a full ArcGIS installation. \n\n# Tutorial\n\nIn order to use **RPyGeo** you need a working ArcMap or ArcGIS Pro installation on your computer. \nIn addition, this tutorial requires the following packages to be installed and attached.\n\n```{r, eval=FALSE}\nlibrary(\"RPyGeo\")\nlibrary(\"sf\")\nlibrary(\"raster\")\nlibrary(\"magrittr\")\n```\n\n**spData** and **RQGIS** must also be installed since we will use the raster object `dem` and the vector object `nz` from these packages to demonstrate both raster and vector operations.\nTo make these datasets available for the subsequent ArcMap geoprocessing, we have to save them on disk first.\nTherefore, we export `nz` and `dem` to a temporary directory.\n\n```{r, eval = FALSE}\ndata(dem, package = \"RQGIS\")\ndata(nz, package = \"spData\")\nwriteRaster(dem, file.path(tempdir(), \"dem.tif\"), format = \"GTiff\")\nst_write(nz, file.path(tempdir(), \"nz.shp\"))\n```\n\n## Establishing the ArcPy Python interface in R\n\nPowered by **reticulate**, `rpygeo_build_env()` will establish an R interface to Python.\nArcPy will only work with the Python binary that comes with the ArcGIS installation.\nIf this Python binary is not installed in the default location (`C:/Python27` in the case of ArcMap and `C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3` in the case of ArcGIS Pro), one has to set it explicitly with the `path` parameter of `rpygeo_build_env()`. \nSecondly, `rpygeo_build_env()` loads the `arcpy` modules.\n\n```{r, eval = FALSE}\narcpy \u003c- rpygeo_build_env(workspace = tempdir(),\n                          overwrite = TRUE,\n                          extensions = \"Spatial\")\n```\n\n`rpygeo_build_env()` lets the user also specify further common ArcGIS environment settings.\nFor instance, setting `overwrite` to `TRUE` lets the user overwrite already existing spatial objects later on with outputs created by ArcPy geoalgorithms.\nThe `extensions` parameter allows also the activation of extensions.^[The availability of extensions is dependent on the purchased ArcGIS license.] The keywords for the `extension` parameter are listed on the ArcGIS [help page](http://desktop.arcgis.com/de/arcmap/10.3/analyze/arcpy-functions/checkoutextension.htm). \nIn the code chunk above, we have enabled the Spatial Analysis extension.\nThe `workspace` parameter defines the default directory where to save the outputs of geoprocessing functions and in which to look for spatial objects. \nNote that the workspace can be a directory or an ESRI file geodatabase.^[If you work with large raster files we would recommend to use a directory, because it takes a long time to load raster datasets from a file geodatabase into an R session.]\nA scratch workspace folder is automatically created inside the workspace. \nThe scratch workspace usually contains the output files of functions that do not explicitly provide an output parameter as is the case for most spatial analyst raster algorithms.\nTo change the default scratch workspace location, use parameter `scratch_workspace`.\n\n## Find out about ArcPy functionality\n\n`rpygeo_search()` is a helper function to find out about the commandline name of all ArcGIS geoalgorithms at our disposal.\n`rpygeo_search()` returns all available algorithms that contain the term specified in `search_term` in their name. \nThe search term can be plain text or a regular expression.\nFor example, to find all ArcPy functions that contain `Classify` in their name, we can type: \n\n```{r, eval=FALSE}\nrpygeo_search(search_term = \"Classify\")\n#\u003e $toolbox\n#\u003e [1] \"ClassifyLasByHeight_3d\" \"ClassifyLasGround_3d\"   \"Reclassify_3d\"         \n#\u003e\n#\u003e $sa\n#\u003e [1] \"ClassifyRaster\" \"MLClassify\"     \"Reclassify\"    \n#\u003e\n#\u003e $main\n#\u003e [1] \"ClassifyLasByHeight_3d\" \"ClassifyLasGround_3d\"   \"Reclassify_3d\"         \n#\u003e \n#\u003e $ddd\n#\u003e [1] \"ClassifyLasByHeight\" \"ClassifyLasGround\"   \"Reclassify\"\n```\n\nThe search result list is divided according to the corresponding modules of the functions (see section [Modules and extensions](#modules-and-extensions)).\n\nIf `search_term` remains unspecified all available functions of the corresponding module will be returned.\n\n`rpygeo_help()` helps to get familiar with the function parameters of a specific ArcGIS geoalgorithm.\n\n```{r, eval=FALSE}\nrpygeo_help(arcpy$Slope_3d)\n```\n\nThe help file is displayed in the viewer pane of RStudio.\nIf you use RPyGeo in another IDE, the help file is displayed in the default browser.\n\n## Geoprocessing with ArcPy\n\nArcPy functions of the main module can be accessed via the `$` operator.\nTaking advantage of the (tab) code completion feature of RStudio, all functions of the ArcPy module are listed after typing the `$` operator (which represents an interactive alternative to `rpygeo_search()`).\n(Tab) code completion will also list the available function parameters for a specific function, e.g. for `arcpy$Slope_3d()`.\nWe will use `arcpy$Slope_3d()` to compute the slope from the digital elevation model (DEM) we have exported at the beginning of this tutorial:\n\n```{r, eval=FALSE}\narcpy$Slope_3d(in_raster = \"dem.tif\", out_raster = \"slope.tif\")\n#\u003eC:\\Users\\janne\\AppData\\Local\\Temp\\RtmpyWYrL1\\slope.tif\n```\n\nExecuting the function creates a file named `slope.tif` in the workspace directory, which in our case is the temporary folder (see above in `rpygeo_build_env()`).\nTo import the output of the ArcGIS processing into R, run:\n\n```{r, eval=FALSE}\nslope \u003c- rpygeo_load(\"slope.tif\")\nplot(slope)\n```\n\n![Slope computed with `Slope_3d()`](https://raw.githubusercontent.com/fapola/RPyGeo/master/vignettes/slope.png)\n\nFigure 1: Slope computed with `Slope_3d()`.\n\n\nThis imports and plots the ArcGIS slope processing output into R as a raster object named `slope` (Figure \\@ref(fig:slope)).\n\nThe pipe operator `%\u003e%` can be used to chain ArcPy function together. \n\n```{r, eval = FALSE}\narcpy$Dissolve_management(in_features = \"nz.shp\", \n                          out_feature_class = \"nz_island.shp\", \n                          dissolve_field = \"Island\") %\u003e%\n  arcpy$PolygonToLine_management(\"nz_border.shp\")\n#\u003eC:\\Users\\janne\\AppData\\Local\\Temp\\RtmpqGHdyf\\nz_border.shp\n```\n\nIn this example the `nz.shp` shapefile is dissolved based on the `Island` field.\nSubsequently, the polygons are converted into polylines (see Figure 2).\n\n![Regions of `nz` (left), `nz` polygons dissolved by island (middle), `nz` polygons converted to lines (right).](https://raw.githubusercontent.com/fapola/RPyGeo/master/vignettes/nz.png)\nFigure 2: Regions of `nz` (left), `nz` polygons dissolved by island (middle), `nz` polygons converted to lines (right).\n\n\n## Modules and extensions\n\nTo use the functions of a specific extension, one has to enable the extension first (see `rpygeo_build_env()`). \nTo access an extension we can also make use of the `$` operator.\nThen, a second `$` provides access to the functions of the extension.\nFor example, to compute the slope from a DEM with the help of the Spatial Analyst extension, we can run:\n\n```{r, eval=FALSE}\narcpy$sa$Slope(in_raster = \"dem.tif\")\n#\u003eC:\\Users\\janne\\AppData\\Local\\Temp\\RtmpqGHdyf/scratch\\Slope_dem1.tif\n```\n\nNote that there is no output parameter, hence the result of the processing will be saved as an Arc/Info Binary Grid file to the scratch workspace location (see again `rpygeo_build_env()`).\nTo save the output to another location, we can make use of `rpygeo_save()`.\nHere, we save the output of the slope processing to the workspace we have defined in the beginning with `rpygeo_build_env()` which was a temporary directory created with `tempdir()`:\n\n```{r, eval=FALSE}\narcpy$sa$Slope(in_raster = \"dem.tif\") %\u003e%\n  rpygeo_save(\"slope.tif\")\n```\n\n## Map algebra\n\nMap algebra expressions can be used in **RPyGeo** with special operators. \nThe four basic calculus functions are implemented as `%rpygeo_+%`, `%rpygeo_-%`, `%rpygeo_*%`, `%rpygeo_/%`. \n\n```{r, eval=FALSE}\n\nras \u003c- arcpy$sa$Raster(\"dem.tif\") \nclass(ras)\n#\u003e\"python.builtin.Raster\" \"python.builtin.object\"\n\nras %rpygeo_+% 2 %\u003e%\n  rpygeo_save(\"dem_2.tif\")\n```\n\nIn this example, `arcpy$sa$Raster()` first creates a Python raster object, which is linked to a temporary Esri Arc/Info Binary Grid stored in the scratch workspace.\nUsing `%rpygeo_+%` we added 2 to each pixel value. \nFor map algebra the `rpygeo_save()` and `rpygeo_load()` functions are very handy, because the output of map algebra operations is always a temporary file. \n\n# Conclusions\n\nPlease note that we could not tested each ArcPy function.\nTherefore, if you encounter any bugs please report them in our [github repository](https://github.com/r-spatial/RPyGeo) under issues or help us fix them them via a pull request.\n\n\n\n# References\n\n* Bivand, R. S., Pebesma, E., \u0026 Gómez-Rubio, V. (2013). Applied Spatial Data Analysis with R (2nd ed.). New York: Springer.\n* Hijmans, R. J. (2017). Raster: Geographic Data Analysis and Modeling.\n* Muenchow, J., Schratz, P., \u0026 Brenning, A. (2017). RQGIS: Integrating R with QGIS for Statistical Geocomputing. The R Journal, 9(2), 409–428.\n* Pebesma, E. (2018). Simple Features for R: Standardized Support for Spatial Vector Data. The R Journal.\n* Pimpler, E. (2015). Programming ArcGis 10.1 with Python Cookbook.\n* Zandbergen, P. A. (2013). Python Scripting for ArcGIS. Redlands: ESRI Press.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-spatial%2Frpygeo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-spatial%2Frpygeo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-spatial%2Frpygeo/lists"}