Integrating R with ArcGIS: Part 2

Cameron Plouffe, Higher Education Developer/Analyst

cplouffe@esri.ca

Tuesday, March 29, 2016

Getting Started with WebEx

  • Listen to the audio broadcast:
    • Phone
  • To maximize your view of the Webinar, click:
  • Click the blue arrow button to return to original view:

Open to Questions

  • Please use the Chat panel:
    • Choose IAIN GREENSMITH, type your question and click Send

  • If you are unable to see the Chat panel, click the Chat button on the top-right corner of your screen:

Webinar Schedule

  • Review of arcgisbinding package
  • What is an R script tool?
    • Basic components of an R script tool
  • Writing an R-ArcGIS script
    • R script tool template
    • Walkthrough of several R-ArcGIS tool scripts
  • Constructing an R script tool in ArcGIS Pro
    • Assigning script tool parameters
    • Tool documentation
  • Using R script tools in ModelBuilder workflows

Review of arcgisbinding Package

The arcgisbinding Package

  • The arcgisbinding package allows R users to access data stored using ArcGIS native data types (e.g., geodatabase feature classes)
    • arc.open, arc.select, arc.write
  • Convert ArcGIS data to an sp object, perform some analysis, and then write back to a geodatabase
    • arc.data2sp, arc.sp2data
  • Convert between WKT and proj.4
    • arc.fromP4ToWkt, arc.fromWktToP4
  • Interact with geometries
    • arc.shapeinfo, arc.shape2sp
  • Package Documentation

Building an R Script Tool

What is an R Script Tool?

  • Similar to Python, ArcGIS allows you to write scripts in R that can be called from within ArcGIS
  • Create geoprocessing (GP) tools that use R for analysis
  • 3 main components to all R script tools
    •  An R script
    • A custom toolbox
    • A definition of the parameters of your script

Basic Components of an R Script

  • All R tool scripts follow the same general form
    • tool_exec
      • Function that will be executed when the R script is called from ArcGIS GP tool
    • in_params
      • First argument of tool_exec
      • List of input parameters provided from a GP tool
    • out_params
      • Second argument of tool_exec
      • List of output parameters provided from a GP tool
      • Required when outputting data to ArcGIS

R Script Tool Functions

  • Certain functions from the arcgisbinding package are only useful in R script tools
    • arc.progress_label
      • Add a description of the current operations being run in R to be displayed in the GP tool dialog box
      • Useful for debugging
    • arc.progress_pos
      • Set the position of the progress bar for a given GP tool

Outputting Data from R

  • Type of data set and output location provided to arc.write() function will determine how the data set is stored
    • Data with spatial attributes will be saved as a GDB feature class or .shp file
    • Tabular data (i.e., a standard data frame) will be saved as a GDB table or .dbf file
  • If a plot is created in an R script tool, it will be displayed in a window from ArcGIS
  • Can also print certain details directly to GP tool dialog box 
    • print, message

R Script Tool Template

One-way ANOVA Example

Building an R Script Tool

  • Once R script with tool_exec() function is complete, can create GP tool in ArcGIS to connect to R script
  • Exact same process as creating a Python GP tool, except that an R script is provided for the Script File
  • Ensure that parameters are ordered in the same way they are referenced within R script
  • Very basic outline of building an R script tool in ArcGIS Pro provided in documents folder of GitHub repository

R-ArcGIS Sample Tools

Model-based Clustering Example

R Script Tools and ModelBuilder

  • R script tools can be incorporated into models built with ModelBuilder in ArcGIS
  • Construct complex workflows powered by R, Python, and native ArcGIS GP tools
  • Model-based Clustering Enhanced example available in R Sample Tools toolbox

Closing

Outreach

  • Very interested in having other members of the R community contribute to the R - ArcGIS Bridge
    • Have questions?  Contact us!
    • Collaboration with R package developers

R Webinar Resources

Thanks

  • R - ArcGIS Bridge Team at Esri US
    • Shaun Walbridge, Mark Janikas, Steve Kopp, Dmitry Pavlushko, Konstantin Krivoruchko
  • ​Hadley Wickham
  • R spatial community

Contact Information

Cameron Plouffe

cplouffe@esri.ca

 

R - ArcGIS Bridge Team

R_bridge@esri.com

Integrating R with ArcGIS: Part 2

By Cam Plouffe

Integrating R with ArcGIS: Part 2

  • 5,255