ArcGIS to R spatial Cheatsheet

ArcGIS to R spatial cheat sheet

Get the pdf version

With thanks to Ross Dwyer for helping out with this one.

We hope you enjoy our cheat sheet for commonly used functions in spatial R packages. Once you are comfortable with R, it very convenient for spatial processing and offers many powerful (and free) statistical packages.

For all functions below xshape is a generic shape (vector) file, xpoly is a polygon shape file, xline is a line shape file, xpoint is a points shape file and xraster is a raster file. Some ARC GIS functions are provided in add-on toolboxes, which we have indicated in brackets. We have provided you with some key functions, for more info see the excellent documentation for each package and their vignette’s.


sp for spatial classes (polygons etc…)
raster for raster classes, raster functions and some functions for shapes.
rgdal for gdal (projections)
rgeos for operations on shapes (e.g. union)
geosphere for great circle distances
maps for standard maps

Loading and saving files

Load a shapefile
readOGR('.', 'filename')
Save a shapefile
writeOGR(xshape, dsn ='dsn', layer = 'layer', driver = 'ESRI Shapefile')
Load a raster
Save a raster
writeRaster(xraster, 'filename', format='ascii')


Operation GIS menu R function
Crop Clip/mask crop(xraster, xextent)
Aggregate cells Aggregate (Spatial Analyst) aggregate(xraster, fact = y)
Disaggregate cells Resample (Data Management) disaggregate(xraster, fact = y)
Change resolution or origin Resample (Data Management) resample(xraster, yraster)
Combine two layers Raster Calculator (Spatial Analyst) overlay(xraster, yraster,fun = xfun)
Shortest distance Euclidean Distance (Spatial Analyst) distance(xraster, xextent)
Distance from a set of points Euclidean Distance (Spatial Analyst) distanceFromPoints(xraster, xpoints)
Area of cells Tabulate Area (Spatial Analyst) area(xraster)
Summary of values Raster Calculator (Spatial Analyst) cellStats(xraster, stat='mean')
Summaries by zones Zonal Geometry (Spatial Analyst) zonal(xraster,zones.raster, fun='mean')
Change projection Project Raster (Data Management) projectRaster(from = xraster, to = yraster, method ='bilinear')


Operation GIS menu R function
All shapes
Clip using a rectangle Clip crop(xpoly)
Select spatial objects by drawing Select select(xpoly)
Clip using a rectangle Clip click(xpoly)
Click on map to identify spatial objects Identity merge(xpoly)
Combine spatial objects Append bind(xpoly)
Query between spatial objects Select over(xpoly)
Coordinates at a location hover mouse over the location locator(1) then click
Aggregate polygons together Dissolve aggregate(xpoly)
Split polygon into separate parts Explode disaggregate(xpoly)
Erase parts of a spatial polygon Erase erase(xpoly)
Intersection of spatial polygons Intersect intersect(xpoly)
Union of spatial polygons Union union(xpoly)
Change a spatial polygon by overlaying values from another Identity and Update cover(xpoly)
Symmetrical differences of spatial polygons Symmetrical Differences symdif(xpoly)
Area of a polygon Geometry calculator gArea(xpoly)
Draw a polygon Create feature drawPoly() then click on figure
Length of a line Geometry calculator gLength(xline)
Distance between points Point distance gDistance(xpoint, byid=T)

Combining shapes and rasters

Operation GIS menu R function
Make a raster from shape PolygonToRaster_conversion rasterize(xshape, xraster)
Make points from a raster RasterToPoint_conversion rasterToPoints(xraster)
Make polygons from a raster RasterToPolygon_conversion rasterToPolygon(xraster)
Query between spatial objects and rasters Sample, Extract by Points, Extract by Polygons (Spatial Analyst) extract(xpoly)

This is an ongoing project, feel free to email us with suggestions. We are keen to improve this cheat sheet, but also keep it simple.
Cheers, Chris and Ross

Chris Brown,
Mar 11, 2015, 10:30 PM