Content

COUNTY CENSUS SUBDIVISION (CCsubdiv) LEVEL

  • Installing the arcbinding package
  • Checking connections with the ArcGIS Pro software and app versions
  • Reading a geodatabase feature class into R
  • Bringing selected fields from a geodatabase feature class into R
  • Converting your R data frame into a spatial data frame object using the arc.data2sp() function
  • Exporting dataframe to CSV

This is a Markdown document on bridging ArcGIS Pro and R. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

Install arcgisbinding and check connections with ArcGIS Pro
library(arcgisbinding)
## *** Please call arc.check_product() to define a desktop license.
arc.check_product()
## product: ArcGIS Pro (13.0.0.36056)
## license: Advanced
## version: 1.0.1.300
Set a working directory
setwd("C:/ArcGIS/Business Analyst/US_2022/Data")
Reading a geodatabase feature class into R
CCsubdiv_df <- arc.open(path = "C:\\ArcGIS\\Business Analyst\\US_2022\\Data\\Demographic Data\\USA_ESRI_2022.gdb\\CountySubdivisions_cs")
Bringing selected fields from a geodatabase feature class into R
CCsubdiv_select_df <- arc.select(object = CCsubdiv_df, fields = c('ID', 'NAME', 'TOTPOP_CY', 'HHPOP_CY', 'FAMPOP_CY', 'GQPOP_CY', 'POPDENS_CY', 'TOTHH_CY', 'AVGHHSZ_CY'))

Convert your R data frame into a spatial data frame object using the arc.data2sp() function

library(sp)
## Warning: package 'sp' was built under R version 4.2.3
CCsubdiv_spdf <- arc.data2sp(CCsubdiv_select_df) 

Rename columns

col_names <- c("County subdiv ID", "County subdiv name", "Total populatio",
               "Household population", "Family population", "Group quarters population",
               "Population density", "Total households", "Average household size")

Assign renamed columns

colnames(CCsubdiv_spdf@data) <- col_names
head(CCsubdiv_spdf@data)
##   County subdiv ID           County subdiv name Total populatio
## 1       0601990390    Caruthers-Raisin City CCD           10043
## 2       0601990530                 Coalinga CCD           18333
## 3       0601991360                    Huron CCD            7129
## 4       0601992630                Riverdale CCD            5544
## 5       0601992820 San Joaquin-Tranquillity CCD            6586
## 6       0603190170                   Avenal CCD           13660
##   Household population Family population Group quarters population
## 1                 9924              8978                       119
## 2                13703             11739                      4630
## 3                 7028              6217                       101
## 4                 5537              5093                         7
## 5                 6523              6108                        63
## 6                 9372              8228                      4288
##   Population density Total households Average household size
## 1               58.1             2704                   3.67
## 2               25.7             4567                   3.00
## 3               22.6             1846                   3.81
## 4               76.8             1545                   3.58
## 5               20.9             1650                   3.95
## 6               44.7             2488                   3.77

Write dataframe with renamed columns to CSV

write.csv(CCsubdiv_spdf@data, file = "CCsubdivSelectedRenamed.csv")

Bring in entire CCsubdiv demographic data - all 404 raws and 2781 columns

CCsubdiv_select_df2 <- arc.select(object = CCsubdiv_df)

Write entire dataframe from the CCsubdiv demographic geodatabase to CSV

write.csv(CCsubdiv_select_df2, file = "CCsubdivAllFields.csv")

End of Markdown document