Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a...

44
Extending ArcGIS with Conda and R Shaun Walbridge

Transcript of Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a...

Page 1: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

ExtendingArcGISwithCondaandRShaunWalbridge

Page 3: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

ExtendingArcGIS

Page 4: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

ExtendingArcGISArcGISisasystemofrecord.Combinedataandanalysisfrommanyfieldsandintoacommonenvironemnt.Whyextend?Can’tdoitall,wesupportover1000GPtools—enablingintegrationwithotherenvironmentstoextendtheplatform.DiscussedSciPyandwhat’s“inthebox”,nowdiscussthebroaderecosystemofopensource.

Page 5: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

Today:RandCondaR-ArcGISBridge

ShortIntroductionDemo

Condaformanagingpackagesandenvironments

IntroductionDemoExercise

Page 6: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

R

Page 7: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

Why ?Powerfulcoredatastructuresandoperations

Dataframes,functionalprogrammingUnparalleledbreadthofstatisticalroutines

ThedefactolanguageofStatisticiansCRAN:6400packagesforsolvingproblemsVersatileandpowerfulplotting

Page 8: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

RDataTypesyou’reusedtoseeing…

Numeric-Integer-Character-Logical-timestampDatatypes

Page 9: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

RDataTypesyou’reusedtoseeing…

Numeric-Integer-Character-Logical-timestamp…butothersyouprobablyaren’t:

vector-matrix-data.frame-factor

Datatypes

Page 10: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

DataFramesTreatstabular(andmulti-dimensional)dataasalabeled,indexedseriesofobservations.Soundssimple,butisagamechangerovertypicalsoftwarewhichisjustdoing2Dlayout(e.g.Excel)

Page 11: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

DataTypes# Create a data frame out of an existing sourcedf.from.csv <- read.csv( "data/growth.csv", header=TRUE)

Page 12: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

DataTypes# Create a data frame from scratchquarter <- c(2, 3, 1)person <- c("Goodchild", "Tobler", "Krige")

met.quota <- c(TRUE, FALSE, TRUE)df <- data.frame(person, met.quota, quarter)

Page 13: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

DataTypesR> df person met.quota quarter1 Goodchild TRUE 22 Tobler FALSE 33 Krige TRUE 1

Page 14: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

0D:SpatialPoints1D:SpatialLines2D:SpatialPolygons3D:Solid4D:Space-time

spTypesEntity+Attributemodel

Page 15: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

StatisticalFormulas

DomainspecificlanguageforstatisticsSimilarpropertiesinotherpartsofthelanguage

formodelspecificationconsistency

fit.results <- lm(pollution ~ elevation + rainfall +

caret

Page 16: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

R—ArcGISBridge

Page 17: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

R—ArcGISBridge

ArcGISdeveloperscancreatetoolsandtoolboxesthatintegrateArcGISandRArcGISuserscanaccessRcodethroughgeoprocessingscriptsRuserscanaccessorganizationsGIS’data,managedintraditionalGISways

https://r-arcgis.github.io

Page 18: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

R—ArcGISBridgeStoreyourdatainArcGIS,accessitquicklyinR,returnRobjectsback

toArcGISnativedatatypes(e.g.geodatabasefeatureclasses).

Knowshowtoconvertspatialdatatospobjects.

PackageDocumentation

Page 19: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

AccessArcGISfromRStartbyloadingthelibrary,andinitializingconnectiontoArcGIS:

# load the ArcGIS-R bridge librarylibrary(arcgisbinding)# initialize the connection to ArcGIS. Only needed when running directly from R.arc.check_product()

Page 20: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

AccessArcGISfromRFirst,selectadatasource(canbeafeatureclass,alayer,oratable):

Then,filterthedatatothesetyouwanttoworkwith(createsin-memorydataframe):

ThiscreatesanArcGISdataframe–lookslikeadataframe,butretainsreferencesbacktothegeometrydata.

input.fc <- arc.open('data.gdb/features')

filtered.df <- arc.select(input.fc, fields=c('fid', 'mean'), where_clause="mean < 100")

Page 21: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

AccessArcGISfromRFinishedwithourworkinR,wanttogetthedatabacktoArcGIS.Writeourresultsbacktoanewfeatureclass,witharc.write:

arc.write('data.gdb/new_features', results.df)

Page 22: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

BuildingRScriptTools

Page 23: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

RArcGISBridgeDemo

DetailsofmodelbasedclusteringanalysisintheRSampleTools

Page 24: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

HowToInstallInstallwiththeRbridgeinstallDetailedinstallationinstructions

Page 25: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

WhereCanIRunThis?

Page 26: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

PackageswithConda

Page 27: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

Whypackagemanagement?

Softwareiscomposedofmanysmallercomponents,oftencalledpackagesorlibraries.It’softenbettertoreusecodethatsolvesaproblemwellratherthanrecreatingitBut,sharingcodeisahardproblem.Doyouhavethesamepackagesofthesameversionsasthedeveloperdid?

Page 28: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

WhyConda?

ScientificPythoncommunityidentifiedthattherewasagapnotbeingaddressedbythecorePythoninfrastructure,limitingtheirabilitytogetpackagesintothehandsofusers

Industrystandardbuiltbypeoplewhocareaboutthisspace—ContinuumAnalytics

Page 29: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

WhyConda?

Itsolvesthehardproblem:

Handlesdependenciesformanylanguages(C,C++,RandofcoursePython)BuiltforPythonfirst,butitreallysolvesamuchbroaderinfrastructuralissue.

Page 30: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

Conda

Page 31: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

Cross-platform:SimplydeveloprecipesforbuildingandinstallingsoftwareonLinux,OSXandWindows.Opensource:Esriisusingit,youcanuseitinyourownprojectsforothercontexts

Whatcanitinstall?Notjustscientificpackages,caninstalleverythingfrominteractiveenvironmentslike to .Spyder JupyterNotebooks

Page 32: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

Environments—CanisolateaPythonenvironment,flexiblymakechangeswithotaffectinginstalledsoftware.Requirements—includeexplicitstateinformation,notjustthepackagename.AlsohandlesplatformsandJupyternotebooks

Page 33: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

Wheredopackagescomefrom?

Condapackagescancomefromavarietyoflocations:

manythousandsofpackagesRepositories(e.g.AnacondaCloud,self-hosted)Ondisk

anaconda.org

Page 34: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

CondaBasics

Condainfoisthestartingpoint—ittellsyouthestateoftheenvironment.

conda --help

conda info

Page 35: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

CondaBasicsconda list

# packages in environment at C:\ArcGIS\bin\Python\envs\arcgispro-py3:#colorama 0.3.7 py35_0 defaultscycler 0.10.0 py35_0 defaultsfuture 0.15.2 py35_0 defaultsmatplotlib 1.5.3 np111py35_0e [arcgispro] esrimpmath 0.19 py35_1 defaultsnetcdf4 1.2.4 py35_0e [arcgispro] esrinose 1.3.7 py35_1 defaultsnumexpr 2.6.1 np111py35_0e [arcgispro] esrinumpy 1.11.2 py35_0e [arcgispro] esripandas 0.19.0 np111py35_0 defaultspip 8.1.2 py35_0 defaultspy 1.4.31 py35_0 defaultspyparsing 2.1.4 py35_0 defaultspypdf2 1.26.0 py_0 esripytest 2.9.2 py35_0 defaultspython 3.5.2 0 defaultspython-dateutil 2.5.3 py35_0 defaultspytz 2016.6.1 py35_0 defaultsrequests 2.11.1 py35_0 defaultsscipy 0.18.1 np111py35_0e [arcgispro] esrisetuptools 27.2.0 py35_1 defaultssympy 1.0 py35_0 defaultswheel 0.29.0 py35_0 defaults

Page 36: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

CondaBasicsActivatingenvironments,acoupleways:

UsetheshortcutsManuallyactivatetheenvironment:

cd C:\ArcGIS\bin\Python\Scripts activate arcgispro-py3

Page 37: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

CondaBasicsAcollectionofpackagesandPythoninstalliscalledanenvironmentorenv,thebuildingblockformanagingPythonwithCondaCanhavemultipleenvironmentsandseamlesslyswitchbetweenthem

Page 38: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

Condavs…Name Means Included?

Conda Thecommanditself ✓Miniconda AminimumsetofPythonpackagesto

buildandrunConda.✓

Anaconda Adistribution200+packagesbuiltwithConda

AnacondaServer

Hostthefullinfrastructureinternally

Page 39: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

DeeperDive

Page 40: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

HowcanIusethis?WealreadyshipyoutheSciPystack—powerfulandoutoftheboxinallproductsCondacommandandaCondarootPythoninstallNewmodules(e.g.requests),environmentwithProCondaUI

Page 41: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

HowcanIusethis?WealreadyshipyoutheSciPystack—powerfulandoutoftheboxinallproductsCondacommandandaCondarootPythoninstallNewmodules(e.g.requests),environmentwithProCondaUIGetpackages,expandyourpossibilityspacePackageyourwork:thisisanopportunitytodistributeit,possiblyincludingcommercialsideaswell.

Page 42: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

CanIRunThis?

ArcGISPro1.3+IsthethePythoninstall.

ArcGISPro1.4UIforConda

Page 43: Extending ArcGIS with Conda and R - 4326.us€¦ · 01/06/2016  · Extending ArcGIS ArcGIS is a system of record. ... from interactive environments like Spyder to Jupyter Notebooks.

CanIRunThis?Future:

IntegrationwithplatformHelpmakethingslikeMGETevenbetterShareresultswithorganizationsandothers