GNRS R package

Brian Maitner

2021-01-21

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")
##                         poldiv_full country_verbatim state_province_verbatim
## 1 United States@Arizona@Pima County    United States                 Arizona
##   state_province_verbatim_alt county_parish_verbatim county_parish_verbatim_alt
## 1                                        Pima County                       Pima
##         country state_province county_parish country_id state_province_id
## 1 United States        Arizona          Pima    6252001           5551752
##   county_parish_id country_iso state_province_iso county_parish_iso geonameid
## 1          5308878          US                 AZ               019   5308878
##   gid_0   gid_1      gid_2 match_method_country match_method_state_province
## 1   USA USA.3_1 USA.3.11_1  exact standard name                  exact name
##   match_method_county_parish match_score_country match_score_state_province
## 1                 exact name                                               
##   match_score_county_parish poldiv_submitted poldiv_matched match_status
## 1                              county_parish  county_parish   full match
##   user_id
## 1       1

#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
## NOTE: Connections to the BIEN database may be limited for the next two weeks, and interruptions to existing connections may occur. Connectivity should be back to normal by Dec. 18, 2020.
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)
##                     poldiv_full country_verbatim state_province_verbatim
## 1   United States@Alabama@Perry    United States                 Alabama
## 2   United States@Alabama@Perry    United States                 Alabama
## 3                      Greece@@           Greece                        
## 4                 New Zealand@@      New Zealand                        
## 5 United States@Arizona@Cochise    United States                 Arizona
## 6                      Greece@@           Greece                        
##   state_province_verbatim_alt county_parish_verbatim county_parish_verbatim_alt
## 1                                              Perry                           
## 2                                              Perry                           
## 3                                                                              
## 4                                                                              
## 5                                            Cochise                           
## 6                                                                              
##         country state_province county_parish country_id state_province_id
## 1 United States        Alabama         Perry    6252001           4829764
## 2 United States        Alabama         Perry    6252001           4829764
## 3        Greece                                  390903                  
## 4   New Zealand                                 2186224                  
## 5 United States        Arizona       Cochise    6252001           5551752
## 6        Greece                                  390903                  
##   county_parish_id country_iso state_province_iso county_parish_iso geonameid
## 1          4082741          US                 AL               105   4082741
## 2          4082741          US                 AL               105   4082741
## 3                           GR                                         390903
## 4                           NZ                                        2186224
## 5          5290270          US                 AZ               003   5290270
## 6                           GR                                         390903
##   gid_0   gid_1      gid_2 match_method_country match_method_state_province
## 1   USA USA.1_1 USA.1.53_1  exact standard name                  exact name
## 2   USA USA.1_1 USA.1.53_1  exact standard name                  exact name
## 3   GRC                     exact standard name                            
## 4   NZL                     exact standard name                            
## 5   USA USA.3_1  USA.3.2_1  exact standard name                  exact name
## 6   GRC                     exact standard name                            
##   match_method_county_parish match_score_country match_score_state_province
## 1     exact ascii short name                                               
## 2     exact ascii short name                                               
## 3                                                                          
## 4                                                                          
## 5     exact ascii short name                                               
## 6                                                                          
##   match_score_county_parish poldiv_submitted poldiv_matched match_status
## 1                              county_parish  county_parish   full match
## 2                              county_parish  county_parish   full match
## 3                                    country        country   full match
## 4                                    country        country   full match
## 5                              county_parish  county_parish   full match
## 6                                    country        country   full match
##   user_id
## 1       1
## 2       2
## 3       3
## 4       4
## 5       5
## 6       6