Content
ZIP CODE LEVEL ANALYSIS
- 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("D:/New Folder/RBridge")
Reading a geodatabase feature class into R
ZIPcode_df <- arc.open(path = "D:\\New Folder\\MyProject2\\MyProject2.gdb\\ZIPCodes_zp_ExportFeatures1")
Bringing selected fields from a geodatabase feature class into R
ZIPcode_select_df <- arc.select(object = ZIPcode_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
ZIPcode_spdf <- arc.data2sp(ZIPcode_select_df)
Rename columns
ZIPcode_col_names <- c("ZIP_code", "City", "Total ZIP code population",
"Household population", "Family population", "Group quarters Population",
"Population density", "Total hHouseholds", "Average household Size")
Assign renamed columns
colnames(ZIPcode_spdf@data) <- ZIPcode_col_names
head(ZIPcode_spdf@data)
## ZIP_code City Total ZIP code population Household population
## 1 94020 La Honda 1785 1758
## 2 94021 Loma Mar 57 55
## 3 94060 Pescadero 1277 1210
## 4 94002 Belmont 28185 27462
## 5 94005 Brisbane 4979 4973
## 6 94010 Burlingame 44837 44246
## Family population Group quarters Population Population density
## 1 1258 27 28.3
## 2 38 2 27.9
## 3 895 67 23.2
## 4 21954 723 5426.5
## 5 3665 6 766.9
## 6 35851 591 3522.5
## Total hHouseholds Average household Size
## 1 765 2.30
## 2 26 2.12
## 3 454 2.67
## 4 10657 2.58
## 5 1992 2.50
## 6 16930 2.61
Write dataframe with renamed columns to CSV
write.csv(ZIPcode_spdf@data, file = "ZIPcodeCSVSelected2.csv")
Bring in entire tract demographic data - all 1776 raws and 2781 columns
ZIPcode_select_df2 <- arc.select(object = ZIPcode_df)
Write entire dataframe from the tract demographic geodatabase to CSV
write.csv(ZIPcode_select_df2, file = "ZIPcodeAllFields2.csv")