Using R scripts as geoprocessing script tools in ArcGIS

If you are a user of R and ArcGIS, you might have wanted to execute the R scripts on your GIS datasets stored within the geodatabases either as feature classes. Recently, Esri has released an ArcGIS R binding (namely a package, arcgisbinding) which makes it possible to create a custom ArcGIS toolbox with a script tool which has its source pointed not to a .py file (for Python script tool), but to an .r file (for R script).

The installation process is outlined at the Esri GitHub page. If you follow the defaults during the installation, make sure you copy the installed arcgisbinding package to the R installation folder, otherwise you will be able to access your ArcGIS datasets within R and RStudio, but your R scripts won’t be executed when run in ArcMap. The detailed steps for fixing this are here.

After you have set everything up, you will be able to do a whole lot of things including but limited to reading Esri file geodatabase data directly from R and loading its datasets into R data frames.

You will also be able to load the geometry of features and accessing their coordinates, which means you can use your favourite R package for working with spatial data (such as sp or rgdal) and then write the output of your operations back into an Esri file geodatabase.

Here is a sample R script which you can point to from a script tool in ArcGIS. Create a script tool with two input parameters (input feature class and input string for state sub region) and one output parameter (.pdf file with the plot).

So, you can run an R script for your Esri based datasets directly from ArcMap. Very handy package many ArcGIS professionals who use R would love to have in their arsenal.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s