GNRS

Brian Maitner

2020-04-23

Geographic Name Resolution Service

The package GNRS is designed to interact with the Geographic Name Resolution Service of the Botanical Information and Ecology Network.

#Installing GNRS

library(devtools)
install_github("EnquistLab/RGNRS/GNRS")

#The easiest case: one political division

library(GNRS)
GNRS_super_simple(country =  "United States", 
                 state_province = "Arizona",
                 county_parish = "Pima County")
##        id                       poldiv_full country_verbatim
## 1 2282338 United States@Arizona@Pima County    United States
##   state_province_verbatim county_parish_verbatim       country state_province
## 1                 Arizona            Pima County United States        Arizona
##   county_parish country_id state_province_id county_parish_id
## 1          Pima    6252001           5551752          5308878
##   match_method_country match_method_state_province match_method_county_parish
## 1  exact standard name                  exact name                 exact name
##   match_score_country match_score_state_province match_score_county_parish
## 1                                                                         
##   poldiv_submitted poldiv_matched match_status user_id
## 1    county_parish  county_parish   full match        
##                                job country_iso state_province_iso
## 1 job_20200423_1145570807554_11997          US                 AZ
##   county_parish_iso
## 1               019

#Multiple political divisions

#First, we'll grab some occurrence records from BIEN

library(BIEN)
## Loading required package: RPostgreSQL
## Loading required package: DBI
## Type vignette("BIEN") or vignette("BIEN_tutorial") to get started
## 
xs <- BIEN_occurrence_species(species = "Xanthium strumarium", political.boundaries = T)


#The GNRS function expects 4 columns as input, but all are optional.
#If you ever forget, you can use the function GNRS_template as a quick lookup, or to populate.

xs_query<-GNRS_template(nrow = nrow(xs))

xs_query$country <- xs$country
xs_query$state_province <- xs$state_province
xs_query$county_parish <- xs$county


xs_gnrs_results <- GNRS(xs_query)

head(xs_gnrs_results)
##        id                         poldiv_full country_verbatim
## 1 2282970 United States@New Mexico@Los Alamos    United States
## 2 2282969    United States@New Mexico@Hidalgo    United States
## 3 2282968    United States@New Mexico@Harding    United States
## 4 2282933         United States@Missouri@Pike    United States
## 5 2282688    United States@Arizona@Santa Cruz    United States
## 6 2282973       United States@New Mexico@Quay    United States
##   state_province_verbatim county_parish_verbatim       country state_province
## 1              New Mexico             Los Alamos United States     New Mexico
## 2              New Mexico                Hidalgo United States     New Mexico
## 3              New Mexico                Harding United States     New Mexico
## 4                Missouri                   Pike United States       Missouri
## 5                 Arizona             Santa Cruz United States        Arizona
## 6              New Mexico                   Quay United States     New Mexico
##   county_parish country_id state_province_id county_parish_id
## 1    Los Alamos    6252001           5481136          5476834
## 2       Hidalgo    6252001           5481136          5471293
## 3       Harding    6252001           5481136          5470675
## 4          Pike    6252001           4398678          4403228
## 5    Santa Cruz    6252001           5551752          5313135
## 6          Quay    6252001           5481136          5485605
##   match_method_country match_method_state_province match_method_county_parish
## 1  exact standard name                  exact name     exact ascii short name
## 2  exact standard name                  exact name     exact ascii short name
## 3  exact standard name                  exact name     exact ascii short name
## 4  exact standard name                  exact name     exact ascii short name
## 5  exact standard name                  exact name     exact ascii short name
## 6  exact standard name                  exact name     exact ascii short name
##   match_score_country match_score_state_province match_score_county_parish
## 1                                                                         
## 2                                                                         
## 3                                                                         
## 4                                                                         
## 5                                                                         
## 6                                                                         
##   poldiv_submitted poldiv_matched match_status user_id
## 1    county_parish  county_parish   full match        
## 2    county_parish  county_parish   full match        
## 3    county_parish  county_parish   full match        
## 4    county_parish  county_parish   full match        
## 5    county_parish  county_parish   full match        
## 6    county_parish  county_parish   full match        
##                                job country_iso state_province_iso
## 1 job_20200423_1145036704478_18047          US                 NM
## 2 job_20200423_1145036704478_18047          US                 NM
## 3 job_20200423_1145036704478_18047          US                 NM
## 4 job_20200423_1145036704478_18047          US                 MO
## 5 job_20200423_1145036704478_18047          US                 AZ
## 6 job_20200423_1145036704478_18047          US                 NM
##   county_parish_iso
## 1               028
## 2               023
## 3               021
## 4               163
## 5               023
## 6               037