Browse Source

much saner return types for all the functions; added the ability to specify extra fields for return values.

pull/3/merge
boB Rudis 7 years ago
parent
commit
d45ea24e4b
No known key found for this signature in database GPG Key ID: 2A514A4997464560
  1. 3
      DESCRIPTION
  2. 1
      NAMESPACE
  3. 35
      R/geocod-batch.R
  4. 58
      R/geocod-one.R
  5. 32
      R/geocod-reverse-batch.R
  6. 29
      R/geocod-reverse.R
  7. 1
      R/rgeocodio-package.R
  8. 27
      README.Rmd
  9. 302
      README.md
  10. 16
      man/gio_batch_geocode.Rd
  11. 10
      man/gio_batch_reverse.Rd
  12. 14
      man/gio_geocode.Rd
  13. 9
      man/gio_geocode_components.Rd
  14. 10
      man/gio_reverse.Rd

3
DESCRIPTION

@ -17,5 +17,6 @@ Depends:
Imports:
purrr,
httr,
jsonlite
jsonlite,
tibble
RoxygenNote: 6.0.1

1
NAMESPACE

@ -9,3 +9,4 @@ export(gio_reverse)
import(httr)
import(purrr)
importFrom(jsonlite,fromJSON)
importFrom(tibble,as_tibble)

35
R/geocod-batch.R

@ -2,29 +2,52 @@
#'
#' @md
#' @param addresses character vector of addresses (10K max)
#' @param fields vector of additional fields to return with query results. Note that these
#' count as extra lookups and impact your dailu quota/costs. See [the official documentation](https://geocod.io/docs/#fields)
#' for more information on costs/pricing. Can be `cd`, `cd113`, `cd114`, or `cd115` for
#' current or historical Congressional districts (U.S.); `stateleg` for State Legislative District (House & Senate, U.S.);
#' `school` forSchool District (elementary/secondary or unified, U.S.); `census` for
#' Census Block/Tract & FIPS codes (U.S.) or `timezone` for timezone.
#' @param api_key `geocod.io` API key
#' @export
#' @examples
#' gio_batch_geocode(c(
#' addresses <- c(
#' "1109 N Highland St, Arlington VA",
#' "525 University Ave, Toronto, ON, Canada",
#' "4410 S Highway 17 92, Casselberry FL",
#' "15000 NE 24th Street, Redmond WA",
#' "17015 Walnut Grove Drive, Morgan Hill CA"
#' ))
gio_batch_geocode <- function(addresses, api_key=gio_auth()) {
#' )
#'
#' gio_batch_geocode(addresses)
#' gio_batch_geocode(addresses, fields=c("cd", "stateleg"))
gio_batch_geocode <- function(addresses, fields, api_key=gio_auth()) {
if (length(addresses) > 10000) {
message("Too many addresses. Submitting first 10,000")
addresses <- addresses[1:10000]
}
params <- list(api_key=api_key)
if (!missing(fields)) params$fields <- paste0(trimws(fields), collapse=",")
res <- httr::POST("https://api.geocod.io/v1/geocode",
query=list(api_key=api_key),
body=as.list(addresses), encode="json")
query=params, body=as.list(addresses), encode="json")
httr::stop_for_status(res)
jsonlite::fromJSON(httr::content(res, as="text", encoding="UTF-8"))
res <- jsonlite::fromJSON(httr::content(res, as="text", encoding = "UTF-8"),
flatten = TRUE)
res <- res$results
new_names <- gsub("\\.", "_", colnames(res))
new_names <- gsub("response_input|address_components|fields", "", new_names)
new_names <- gsub("[_]+", "_", new_names)
new_names <- sub("^_", "", new_names)
res <- set_names(res, new_names)
as_tibble(res)
}

58
R/geocod-one.R

@ -2,18 +2,40 @@
#'
#' @md
#' @param address address to geocode
#' @param fields vector of additional fields to return with query results. Note that these
#' count as extra lookups and impact your dailu quota/costs. See [the official documentation](https://geocod.io/docs/#fields)
#' for more information on costs/pricing. Can be `cd`, `cd113`, `cd114`, or `cd115` for
#' current or historical Congressional districts (U.S.); `stateleg` for State Legislative District (House & Senate, U.S.);
#' `school` forSchool District (elementary/secondary or unified, U.S.); `census` for
#' Census Block/Tract & FIPS codes (U.S.) or `timezone` for timezone.
#' @param api_key `geocod.io` API key
#' @export
#' @examples
#' gio_geocode("1109 N Highland St, Arlington, VA")
gio_geocode <- function(address, api_key=gio_auth()) {
#' @examples \dontrun{
#' gio_geocode("1109 N Highland St, Arlcdceington, VA")
#' gio_geocode("1109 N Highland St, Arlington, VA",
#' fields=c("cd", "stateleg"))
#' }
gio_geocode <- function(address, fields, api_key=gio_auth()) {
params <- list(q=address, api_key=api_key)
if (!missing(fields)) params$fields <- paste0(trimws(fields), collapse=",")
res <- httr::GET("https://api.geocod.io/v1/geocode",
query=list(q=address, api_key=api_key))
res <- httr::GET("https://api.geocod.io/v1/geocode", query=params)
httr::stop_for_status(res)
jsonlite::fromJSON(httr::content(res, as="text", encoding="UTF-8"))
res <- jsonlite::fromJSON(httr::content(res, as="text", encoding = "UTF-8"),
flatten = TRUE)
res <- res$results
new_names <- gsub("\\.", "_", colnames(res))
new_names <- gsub("address_components|fields", "", new_names)
new_names <- sub("^_", "", new_names)
res <- set_names(res, new_names)
as_tibble(res)
}
@ -21,14 +43,23 @@ gio_geocode <- function(address, api_key=gio_auth()) {
#'
#' @md
#' @param street,city,state,postal_code,country address components
#' @param fields vector of additional fields to return with query results. Note that these
#' count as extra lookups and impact your dailu quota/costs. See [the official documentation](https://geocod.io/docs/#fields)
#' for more information on costs/pricing. Can be `cd`, `cd113`, `cd114`, or `cd115` for
#' current or historical Congressional districts (U.S.); `stateleg` for State Legislative District (House & Senate, U.S.);
#' `school` forSchool District (elementary/secondary or unified, U.S.); `census` for
#' Census Block/Tract & FIPS codes (U.S.) or `timezone` for timezone.
#' @param api_key `geocod.io` API key
#' @export
#' @examples
#' gio_geocode_components("1109 N Highland St", "Arlington", "VA")
#' gio_geocode_components("1109 N Highland St", "Arlington", "VA",
#' fields=c("census", "stateleg"))
gio_geocode_components <- function(street, city, state, postal_code, country,
api_key=gio_auth()) {
fields, api_key=gio_auth()) {
params <- list(api_key=api_key)
if (!missing(fields)) params$fields <- paste0(trimws(fields), collapse=",")
if (!missing(street)) params$street <- street
if (!missing(city)) params$city <- city
@ -40,6 +71,17 @@ gio_geocode_components <- function(street, city, state, postal_code, country,
httr::stop_for_status(res)
jsonlite::fromJSON(httr::content(res, as="text", encoding="UTF-8"))
res <- jsonlite::fromJSON(httr::content(res, as="text", encoding = "UTF-8"),
flatten = TRUE)
res <- res$results
new_names <- gsub("\\.", "_", colnames(res))
new_names <- gsub("address_components|fields", "", new_names)
new_names <- sub("^_", "", new_names)
res <- set_names(res, new_names)
as_tibble(res)
}

32
R/geocod-reverse-batch.R

@ -2,6 +2,12 @@
#'
#' @md
#' @param coordinates data frame of coordinates with `lat` and `lon` columns
#' @param fields vector of additional fields to return with query results. Note that these
#' count as extra lookups and impact your dailu quota/costs. See [the official documentation](https://geocod.io/docs/#fields)
#' for more information on costs/pricing. Can be `cd`, `cd113`, `cd114`, or `cd115` for
#' current or historical Congressional districts (U.S.); `stateleg` for State Legislative District (House & Senate, U.S.);
#' `school` forSchool District (elementary/secondary or unified, U.S.); `census` for
#' Census Block/Tract & FIPS codes (U.S.) or `timezone` for timezone.
#' @param api_key `geocod.io` API key
#' @export
#' @examples
@ -10,7 +16,8 @@
#' lon = c(-77.9658000, -96.6303900, -117.8362320, -80.6784760)
#' ) -> to_code
#' gio_batch_reverse(to_code)
gio_batch_reverse <- function(coordinates, api_key=gio_auth()) {
#' gio_batch_reverse(to_code, fields=c("census", "stateleg"))
gio_batch_reverse <- function(coordinates, fields, api_key=gio_auth()) {
if (nrow(coordinates) > 10000) {
message("Too many addresses. Submitting first 10,000")
@ -27,13 +34,28 @@ gio_batch_reverse <- function(coordinates, api_key=gio_auth()) {
pairs <- sprintf("%s,%s", coordinates$lat, coordinates$lon)
params <- list(api_key=api_key)
if (!missing(fields)) params$fields <- paste0(trimws(fields), collapse=",")
res <- httr::POST("https://api.geocod.io/v1/reverse",
query=list(api_key=api_key),
body=as.list(pairs), encode="json")
query=params, body=as.list(pairs), encode="json")
httr::stop_for_status(res)
jsonlite::fromJSON(httr::content(res, as="text", encoding="UTF-8"))
res <- jsonlite::fromJSON(httr::content(res, as="text", encoding = "UTF-8"),
flatten = TRUE)
res <- res$results$response.results
res <- map_df(res, ~.)
new_names <- gsub("\\.", "_", colnames(res))
new_names <- gsub("response_input|address_components|fields", "", new_names)
new_names <- gsub("[_]+", "_", new_names)
new_names <- sub("^_", "", new_names)
res <- set_names(res, new_names)
}
as_tibble(res)
}

29
R/geocod-reverse.R

@ -3,16 +3,37 @@
#' @md
#' @param lat,lon lat/lon pair to reverse geocode
#' @param api_key `geocod.io` API key
#' @param fields vector of additional fields to return with query results. Note that these
#' count as extra lookups and impact your dailu quota/costs. See [the official documentation](https://geocod.io/docs/#fields)
#' for more information on costs/pricing. Can be `cd`, `cd113`, `cd114`, or `cd115` for
#' current or historical Congressional districts (U.S.); `stateleg` for State Legislative District (House & Senate, U.S.);
#' `school` forSchool District (elementary/secondary or unified, U.S.); `census` for
#' Census Block/Tract & FIPS codes (U.S.) or `timezone` for timezone.
#' @export
#' @returh `tibble`
#' @examples
#' gio_reverse(38.9002898, -76.9990361)
gio_reverse <- function(lat, lon, api_key=gio_auth()) {
#' gio_reverse(38.9002898, -76.9990361, fields=c("census", "stateleg"))
gio_reverse <- function(lat, lon, fields, api_key=gio_auth()) {
res <- httr::GET("https://api.geocod.io/v1/reverse",
query=list(q=sprintf("%s,%s", lat, lon), api_key=api_key))
params <- list(q=sprintf("%s,%s", lat, lon), api_key=api_key)
if (!missing(fields)) params$fields <- paste0(trimws(fields), collapse=",")
res <- httr::GET("https://api.geocod.io/v1/reverse", query=params)
httr::stop_for_status(res)
jsonlite::fromJSON(httr::content(res, as="text", encoding="UTF-8"))
res <- jsonlite::fromJSON(httr::content(res, as="text", encoding = "UTF-8"),
flatten = TRUE)
res <- res$results
new_names <- gsub("\\.", "_", colnames(res))
new_names <- gsub("address_components|fields", "", new_names)
new_names <- sub("^_", "", new_names)
res <- set_names(res, new_names)
as_tibble(res)
}

1
R/rgeocodio-package.R

@ -8,4 +8,5 @@
#' @author Bob Rudis (bob@@rud.is)
#' @import purrr httr
#' @importFrom jsonlite fromJSON
#' @importFrom tibble as_tibble
NULL

27
README.Rmd

@ -15,10 +15,12 @@ The following functions are implemented:
- `gio_geocode_components`: Geocode a single address
- `gio_reverse`: Reverse geocode a single lat/lon pair
All functions return tidy `tibble`s with sane column names.
### TODO
- enable selection of additional fields
- better return types
- <strike>enable selection of additional fields</strike>
- <strike>better return types</strike>
- more error checking
- tests
@ -46,13 +48,15 @@ gio_geocode_components("1109 N Highland St", "Arlington", "VA")
gio_reverse(38.9002898, -76.9990361)
gio_batch_geocode(c(
addresses <- c(
"1109 N Highland St, Arlington VA",
"525 University Ave, Toronto, ON, Canada",
"4410 S Highway 17 92, Casselberry FL",
"15000 NE 24th Street, Redmond WA",
"17015 Walnut Grove Drive, Morgan Hill CA"
))
)
gio_batch_geocode(addresses)
data.frame(
lat = c(35.9746000, 32.8793700, 33.8337100, 35.4171240),
@ -62,6 +66,21 @@ data.frame(
gio_batch_reverse(to_code)
```
### Extra Fields
```{r message=FALSE, warning=FALSE, error=FALSE}
gio_geocode("1109 N Highland St, Arlington, VA", fields=c("cd", "stateleg"))
gio_geocode_components("1109 N Highland St", "Arlington", "VA",
fields=c("census", "stateleg"))
gio_reverse(38.9002898, -76.9990361, fields=c("census", "stateleg"))
gio_batch_geocode(addresses, fields=c("cd", "stateleg"))
gio_batch_reverse(to_code, fields=c("census", "stateleg"))
```
### Test Results
```{r message=FALSE, warning=FALSE, error=FALSE}

302
README.md

@ -12,10 +12,12 @@ The following functions are implemented:
- `gio_geocode_components`: Geocode a single address
- `gio_reverse`: Reverse geocode a single lat/lon pair
All functions return tidy `tibble`s with sane column names.
### TODO
- enable selection of additional fields
- better return types
- <strike>enable selection of additional fields</strike>
- <strike>better return types</strike>
- more error checking
- tests
@ -40,167 +42,59 @@ packageVersion("rgeocodio")
gio_geocode("1109 N Highland St, Arlington, VA")
```
## $input
## $input$address_components
## $input$address_components$number
## [1] "1109"
##
## $input$address_components$predirectional
## [1] "N"
##
## $input$address_components$street
## [1] "Highland"
##
## $input$address_components$suffix
## [1] "St"
##
## $input$address_components$formatted_street
## [1] "N Highland St"
##
## $input$address_components$city
## [1] "Arlington"
##
## $input$address_components$state
## [1] "VA"
##
## $input$address_components$zip
## [1] "22201"
##
## $input$address_components$country
## [1] "US"
##
##
## $input$formatted_address
## [1] "1109 N Highland St, Arlington, VA 22201"
##
##
## $results
## address_components.number address_components.predirectional address_components.street address_components.suffix
## 1 1109 N Highland St
## address_components.formatted_street address_components.city address_components.county address_components.state
## 1 N Highland St Arlington Arlington County VA
## address_components.zip address_components.country formatted_address location.lat location.lng
## 1 22201 US 1109 N Highland St, Arlington, VA 22201 38.88667 -77.09473
## accuracy accuracy_type source
## 1 1 rooftop Virginia GIS Clearinghouse
## # A tibble: 1 × 16
## formatted_address accuracy accuracy_type source number predirectional
## * <chr> <int> <chr> <chr> <chr> <chr>
## 1 1109 N Highland St, Arlington, VA 22201 1 rooftop Virginia GIS Clearinghouse 1109 N
## # ... with 10 more variables: street <chr>, suffix <chr>, formatted_street <chr>, city <chr>, county <chr>,
## # state <chr>, zip <chr>, country <chr>, location_lat <dbl>, location_lng <dbl>
``` r
gio_geocode_components("1109 N Highland St", "Arlington", "VA")
```
## $input
## $input$address_components
## $input$address_components$number
## [1] "1109"
##
## $input$address_components$predirectional
## [1] "N"
##
## $input$address_components$street
## [1] "Highland"
##
## $input$address_components$suffix
## [1] "St"
##
## $input$address_components$formatted_street
## [1] "N Highland St"
##
## $input$address_components$city
## [1] "Arlington"
##
## $input$address_components$state
## [1] "VA"
##
## $input$address_components$zip
## [1] "22201"
##
## $input$address_components$country
## [1] "US"
##
##
## $input$formatted_address
## [1] "1109 N Highland St, Arlington, VA 22201"
##
##
## $results
## address_components.number address_components.predirectional address_components.street address_components.suffix
## 1 1109 N Highland St
## address_components.formatted_street address_components.city address_components.county address_components.state
## 1 N Highland St Arlington Arlington County VA
## address_components.zip address_components.country formatted_address location.lat location.lng
## 1 22201 US 1109 N Highland St, Arlington, VA 22201 38.88667 -77.09473
## accuracy accuracy_type source
## 1 1 rooftop Virginia GIS Clearinghouse
## # A tibble: 1 × 16
## formatted_address accuracy accuracy_type source number predirectional
## * <chr> <int> <chr> <chr> <chr> <chr>
## 1 1109 N Highland St, Arlington, VA 22201 1 rooftop Virginia GIS Clearinghouse 1109 N
## # ... with 10 more variables: street <chr>, suffix <chr>, formatted_street <chr>, city <chr>, county <chr>,
## # state <chr>, zip <chr>, country <chr>, location_lat <dbl>, location_lng <dbl>
``` r
gio_reverse(38.9002898, -76.9990361)
```
## $results
## address_components.number address_components.street address_components.suffix address_components.postdirectional
## 1 500 H St NE
## 2 800 5th St NE
## 3 474 H St NE
## address_components.formatted_street address_components.city address_components.county address_components.state
## 1 H St NE Washington District of Columbia DC
## 2 5th St NE Washington District of Columbia DC
## 3 H St NE Washington District of Columbia DC
## address_components.zip address_components.country formatted_address location.lat location.lng
## 1 20002 US 500 H St NE, Washington, DC 20002 38.9002 -76.99951
## 2 20002 US 800 5th St NE, Washington, DC 20002 38.9002 -76.99951
## 3 20002 US 474 H St NE, Washington, DC 20002 38.9002 -76.99994
## accuracy accuracy_type source
## 1 1.00 nearest_street TIGER/Line® dataset from the US Census Bureau
## 2 0.18 nearest_street TIGER/Line® dataset from the US Census Bureau
## 3 0.18 nearest_street TIGER/Line® dataset from the US Census Bureau
## # A tibble: 3 × 16
## formatted_address accuracy accuracy_type source number
## * <chr> <dbl> <chr> <chr> <chr>
## 1 500 H St NE, Washington, DC 20002 1.00 nearest_street TIGER/Line® dataset from the US Census Bureau 500
## 2 800 5th St NE, Washington, DC 20002 0.18 nearest_street TIGER/Line® dataset from the US Census Bureau 800
## 3 474 H St NE, Washington, DC 20002 0.18 nearest_street TIGER/Line® dataset from the US Census Bureau 474
## # ... with 11 more variables: street <chr>, suffix <chr>, postdirectional <chr>, formatted_street <chr>, city <chr>,
## # county <chr>, state <chr>, zip <chr>, country <chr>, location_lat <dbl>, location_lng <dbl>
``` r
gio_batch_geocode(c(
addresses <- c(
"1109 N Highland St, Arlington VA",
"525 University Ave, Toronto, ON, Canada",
"4410 S Highway 17 92, Casselberry FL",
"15000 NE 24th Street, Redmond WA",
"17015 Walnut Grove Drive, Morgan Hill CA"
))
)
gio_batch_geocode(addresses)
```
## $results
## query response.input.address_components.number
## 1 1109 N Highland St, Arlington VA 1109
## 2 525 University Ave, Toronto, ON, Canada 525
## 3 4410 S Highway 17 92, Casselberry FL 4410
## 4 15000 NE 24th Street, Redmond WA 15000
## 5 17015 Walnut Grove Drive, Morgan Hill CA 17015
## response.input.address_components.predirectional response.input.address_components.street
## 1 N Highland
## 2 <NA> University
## 3 <NA> State Rte 17
## 4 NE 24th
## 5 <NA> Walnut Grove
## response.input.address_components.suffix response.input.address_components.formatted_street
## 1 St N Highland St
## 2 Ave University Ave
## 3 <NA> State Rte 17
## 4 St NE 24th St
## 5 Dr Walnut Grove Dr
## response.input.address_components.city response.input.address_components.state response.input.address_components.zip
## 1 Arlington VA 22201
## 2 Toronto ON <NA>
## 3 Casselberry FL 32707
## 4 Redmond WA 98052
## 5 Morgan Hill CA 95037
## response.input.address_components.country response.input.formatted_address
## 1 US 1109 N Highland St, Arlington, VA 22201
## 2 CA 525 University Ave, Toronto, ON
## 3 US 4410 State Rte 17, Casselberry, FL 32707
## 4 US 15000 NE 24th St, Redmond, WA 98052
## 5 US 17015 Walnut Grove Dr, Morgan Hill, CA 95037
## response.results
## 1 1109, N, Highland, St, N Highland St, Arlington, Arlington County, VA, 22201, US, 1109 N Highland St, Arlington, VA 22201, 38.886665, -77.094733, 1, rooftop, Virginia GIS Clearinghouse
## 2 525, University, Ave, University Ave, Toronto, ON, CA, 525 University Ave, Toronto, ON, 43.656258, -79.388223, 1, rooftop, City of Toronto Open Data
## 3 4410, 4410, Us Hwy 17, Us Hwy 17, Us Hwy 17, Us Hwy 17, Casselberry, Casselberry, Seminole County, Seminole County, FL, FL, 32707, 32707, US, US, 4410 Us Hwy 17, Casselberry, FL 32707, 4410 Us Hwy 17, Casselberry, FL 32707, 28.671168, 28.670668, -81.33834, -81.338163, 1, 0.8, range_interpolation, range_interpolation, TIGER/Line® dataset from the US Census Bureau, TIGER/Line® dataset from the US Census Bureau
## 4 15000, 15000, NE, NE, 24th, 24th, St, St, NE 24th St, NE 24th St, Redmond, Redmond, King County, King County, WA, WA, 98052, 98052, US, US, 15000 NE 24th St, Redmond, WA 98052, 15000 NE 24th St, Redmond, WA 98052, 47.631663, 47.631363, -122.141532, -122.141535, 1, 0.8, range_interpolation, range_interpolation, TIGER/Line® dataset from the US Census Bureau, TIGER/Line® dataset from the US Census Bureau
## 5 Walnut Grove, Dr, Walnut Grove Dr, Morgan Hill, Santa Clara County, CA, 95037, US, Walnut Grove Dr, Morgan Hill, CA 95037, 37.138619, -121.64061, 0.8, street_center, TIGER/Line® dataset from the US Census Bureau
## # A tibble: 5 × 12
## query response_results formatted_address number
## * <chr> <list> <chr> <chr>
## 1 1109 N Highland St, Arlington VA <data.frame [1 × 16]> 1109 N Highland St, Arlington, VA 22201 1109
## 2 525 University Ave, Toronto, ON, Canada <data.frame [1 × 13]> 525 University Ave, Toronto, ON 525
## 3 4410 S Highway 17 92, Casselberry FL <data.frame [2 × 14]> 4410 State Rte 17, Casselberry, FL 32707 4410
## 4 15000 NE 24th Street, Redmond WA <data.frame [2 × 16]> 15000 NE 24th St, Redmond, WA 98052 15000
## 5 17015 Walnut Grove Drive, Morgan Hill CA <data.frame [1 × 14]> 17015 Walnut Grove Dr, Morgan Hill, CA 95037 17015
## # ... with 8 more variables: predirectional <chr>, street <chr>, suffix <chr>, formatted_street <chr>, city <chr>,
## # state <chr>, zip <chr>, country <chr>
``` r
data.frame(
@ -211,17 +105,113 @@ data.frame(
gio_batch_reverse(to_code)
```
## $results
## query
## 1 35.9746,-77.9658
## 2 32.87937,-96.63039
## 3 33.83371,-117.836232
## 4 35.417124,-80.678476
## results
## 1 101, 100, 125, State Hwy 58, Alston, Alston, State Hwy 58, N Alston St, S Alston St, Nashville, Nashville, Nashville, Nash County, Nash County, Nash County, NC, NC, NC, 27856, 27856, 27856, US, US, US, NA, N, S, NA, St, St, 101 State Hwy 58, Nashville, NC 27856, 100 N Alston St, Nashville, NC 27856, 125 S Alston St, Nashville, NC 27856, 35.974536, 35.974536, 35.974263, -77.965716, -77.965716, -77.965823, 1, 0.37, 0.36, nearest_street, nearest_street, nearest_street, TIGER/Line® dataset from the US Census Bureau, TIGER/Line® dataset from the US Census Bureau, TIGER/Line® dataset from the US Census Bureau
## 2 100, 2961, 3084, E, S, S, Kingsley, 1st, 1st, Rd, St, St, E Kingsley Rd, S 1st St, S 1st St, Garland, Garland, Garland, Dallas County, Dallas County, Dallas County, TX, TX, TX, 75041, 75041, 75041, US, US, US, 100 E Kingsley Rd, Garland, TX 75041, 2961 S 1st St, Garland, TX 75041, 3084 S 1st St, Garland, TX 75041, 32.878693, 32.881541, 32.878897, -96.630918, -96.630962, -96.630992, 1, 0.92, 0.87, nearest_street, nearest_street, nearest_street, TIGER/Line® dataset from the US Census Bureau, TIGER/Line® dataset from the US Census Bureau, TIGER/Line® dataset from the US Census Bureau
## 3 2700, 2566, 2790, N, N, N, Tustin, Tustin, Tustin, St, St, St, N Tustin St, N Tustin St, N Tustin St, Orange, Orange, Orange, Orange County, Orange County, Orange County, CA, CA, CA, 92865, 92865, 92865, US, US, US, 2700 N Tustin St, Orange, CA 92865, 2566 N Tustin St, Orange, CA 92865, 2790 N Tustin St, Orange, CA 92865, 33.832923, 33.830224, 33.834775, -117.836211, -117.836152, -117.836249, 1, 0, 0, nearest_street, nearest_street, nearest_street, TIGER/Line® dataset from the US Census Bureau, TIGER/Line® dataset from the US Census Bureau, TIGER/Line® dataset from the US Census Bureau
## 4 5968, 5500, 450, Village, York, Sportsman, Dr, St, Dr, NW, NW, NA, Village Dr NW, York St NW, Sportsman Dr, Concord, Concord, Concord, Cabarrus County, Cabarrus County, Cabarrus County, NC, NC, NC, 28027, 28027, 28027, US, US, US, 5968 Village Dr NW, Concord, NC 28027, 5500 York St NW, Concord, NC 28027, 450 Sportsman Dr, Concord, NC 28027, 35.413592, 35.41373, 35.420958, -80.675786, -80.67508, -80.675289, 1, 0.92, 0.89, nearest_street, nearest_street, nearest_street, TIGER/Line® dataset from the US Census Bureau, TIGER/Line® dataset from the US Census Bureau, TIGER/Line® dataset from the US Census Bureau
## # A tibble: 12 × 17
## formatted_address accuracy accuracy_type source number
## <chr> <dbl> <chr> <chr> <chr>
## 1 101 State Hwy 58, Nashville, NC 27856 1.00 nearest_street TIGER/Line® dataset from the US Census Bureau 101
## 2 100 N Alston St, Nashville, NC 27856 0.37 nearest_street TIGER/Line® dataset from the US Census Bureau 100
## 3 125 S Alston St, Nashville, NC 27856 0.36 nearest_street TIGER/Line® dataset from the US Census Bureau 125
## 4 100 E Kingsley Rd, Garland, TX 75041 1.00 nearest_street TIGER/Line® dataset from the US Census Bureau 100
## 5 2961 S 1st St, Garland, TX 75041 0.92 nearest_street TIGER/Line® dataset from the US Census Bureau 2961
## 6 3084 S 1st St, Garland, TX 75041 0.87 nearest_street TIGER/Line® dataset from the US Census Bureau 3084
## 7 2700 N Tustin St, Orange, CA 92865 1.00 nearest_street TIGER/Line® dataset from the US Census Bureau 2700
## 8 2566 N Tustin St, Orange, CA 92865 0.00 nearest_street TIGER/Line® dataset from the US Census Bureau 2566
## 9 2790 N Tustin St, Orange, CA 92865 0.00 nearest_street TIGER/Line® dataset from the US Census Bureau 2790
## 10 5968 Village Dr NW, Concord, NC 28027 1.00 nearest_street TIGER/Line® dataset from the US Census Bureau 5968
## 11 5500 York St NW, Concord, NC 28027 0.92 nearest_street TIGER/Line® dataset from the US Census Bureau 5500
## 12 450 Sportsman Dr, Concord, NC 28027 0.89 nearest_street TIGER/Line® dataset from the US Census Bureau 450
## # ... with 12 more variables: street <chr>, formatted_street <chr>, city <chr>, county <chr>, state <chr>, zip <chr>,
## # country <chr>, predirectional <chr>, suffix <chr>, location_lat <dbl>, location_lng <dbl>, postdirectional <chr>
### Extra Fields
``` r
gio_geocode("1109 N Highland St, Arlington, VA", fields=c("cd", "stateleg"))
```
## # A tibble: 1 × 24
## formatted_address accuracy accuracy_type source number predirectional
## * <chr> <int> <chr> <chr> <chr> <chr>
## 1 1109 N Highland St, Arlington, VA 22201 1 rooftop Virginia GIS Clearinghouse 1109 N
## # ... with 18 more variables: street <chr>, suffix <chr>, formatted_street <chr>, city <chr>, county <chr>,
## # state <chr>, zip <chr>, country <chr>, location_lat <dbl>, location_lng <dbl>, congressional_district_name <chr>,
## # congressional_district_district_number <int>, congressional_district_congress_number <chr>,
## # congressional_district_congress_years <chr>, state_legislative_districts_senate_name <chr>,
## # state_legislative_districts_senate_district_number <chr>, state_legislative_districts_house_name <chr>,
## # state_legislative_districts_house_district_number <chr>
``` r
gio_geocode_components("1109 N Highland St", "Arlington", "VA",
fields=c("census", "stateleg"))
```
## # A tibble: 1 × 27
## formatted_address accuracy accuracy_type source number predirectional
## * <chr> <int> <chr> <chr> <chr> <chr>
## 1 1109 N Highland St, Arlington, VA 22201 1 rooftop Virginia GIS Clearinghouse 1109 N
## # ... with 21 more variables: street <chr>, suffix <chr>, formatted_street <chr>, city <chr>, county <chr>,
## # state <chr>, zip <chr>, country <chr>, location_lat <dbl>, location_lng <dbl>,
## # state_legislative_districts_senate_name <chr>, state_legislative_districts_senate_district_number <chr>,
## # state_legislative_districts_house_name <chr>, state_legislative_districts_house_district_number <chr>,
## # census_census_year <int>, census_state_fips <chr>, census_county_fips <chr>, census_place_fips <chr>,
## # census_tract_code <chr>, census_block_code <chr>, census_block_group <chr>
``` r
gio_reverse(38.9002898, -76.9990361, fields=c("census", "stateleg"))
```
## # A tibble: 3 × 25
## formatted_address accuracy accuracy_type source number
## * <chr> <dbl> <chr> <chr> <chr>
## 1 500 H St NE, Washington, DC 20002 1.00 nearest_street TIGER/Line® dataset from the US Census Bureau 500
## 2 800 5th St NE, Washington, DC 20002 0.18 nearest_street TIGER/Line® dataset from the US Census Bureau 800
## 3 474 H St NE, Washington, DC 20002 0.18 nearest_street TIGER/Line® dataset from the US Census Bureau 474
## # ... with 20 more variables: street <chr>, suffix <chr>, postdirectional <chr>, formatted_street <chr>, city <chr>,
## # county <chr>, state <chr>, zip <chr>, country <chr>, location_lat <dbl>, location_lng <dbl>,
## # state_legislative_districts_senate_name <chr>, state_legislative_districts_senate_district_number <chr>,
## # census_census_year <int>, census_state_fips <chr>, census_county_fips <chr>, census_place_fips <chr>,
## # census_tract_code <chr>, census_block_code <chr>, census_block_group <chr>
``` r
gio_batch_geocode(addresses, fields=c("cd", "stateleg"))
```
## # A tibble: 5 × 12
## query response_results formatted_address number
## * <chr> <list> <chr> <chr>
## 1 1109 N Highland St, Arlington VA <data.frame [1 × 24]> 1109 N Highland St, Arlington, VA 22201 1109
## 2 525 University Ave, Toronto, ON, Canada <data.frame [1 × 13]> 525 University Ave, Toronto, ON 525
## 3 4410 S Highway 17 92, Casselberry FL <data.frame [2 × 22]> 4410 State Rte 17, Casselberry, FL 32707 4410
## 4 15000 NE 24th Street, Redmond WA <data.frame [2 × 24]> 15000 NE 24th St, Redmond, WA 98052 15000
## 5 17015 Walnut Grove Drive, Morgan Hill CA <data.frame [1 × 22]> 17015 Walnut Grove Dr, Morgan Hill, CA 95037 17015
## # ... with 8 more variables: predirectional <chr>, street <chr>, suffix <chr>, formatted_street <chr>, city <chr>,
## # state <chr>, zip <chr>, country <chr>
``` r
gio_batch_reverse(to_code, fields=c("census", "stateleg"))
```
## # A tibble: 12 × 28
## formatted_address accuracy accuracy_type source number
## <chr> <dbl> <chr> <chr> <chr>
## 1 101 State Hwy 58, Nashville, NC 27856 1.00 nearest_street TIGER/Line® dataset from the US Census Bureau 101
## 2 100 N Alston St, Nashville, NC 27856 0.37 nearest_street TIGER/Line® dataset from the US Census Bureau 100
## 3 125 S Alston St, Nashville, NC 27856 0.36 nearest_street TIGER/Line® dataset from the US Census Bureau 125
## 4 100 E Kingsley Rd, Garland, TX 75041 1.00 nearest_street TIGER/Line® dataset from the US Census Bureau 100
## 5 2961 S 1st St, Garland, TX 75041 0.92 nearest_street TIGER/Line® dataset from the US Census Bureau 2961
## 6 3084 S 1st St, Garland, TX 75041 0.87 nearest_street TIGER/Line® dataset from the US Census Bureau 3084
## 7 2700 N Tustin St, Orange, CA 92865 1.00 nearest_street TIGER/Line® dataset from the US Census Bureau 2700
## 8 2566 N Tustin St, Orange, CA 92865 0.00 nearest_street TIGER/Line® dataset from the US Census Bureau 2566
## 9 2790 N Tustin St, Orange, CA 92865 0.00 nearest_street TIGER/Line® dataset from the US Census Bureau 2790
## 10 5968 Village Dr NW, Concord, NC 28027 1.00 nearest_street TIGER/Line® dataset from the US Census Bureau 5968
## 11 5500 York St NW, Concord, NC 28027 0.92 nearest_street TIGER/Line® dataset from the US Census Bureau 5500
## 12 450 Sportsman Dr, Concord, NC 28027 0.89 nearest_street TIGER/Line® dataset from the US Census Bureau 450
## # ... with 23 more variables: street <chr>, formatted_street <chr>, city <chr>, county <chr>, state <chr>, zip <chr>,
## # country <chr>, predirectional <chr>, suffix <chr>, location_lat <dbl>, location_lng <dbl>,
## # state_legislative_districts_senate_name <chr>, state_legislative_districts_senate_district_number <chr>,
## # state_legislative_districts_house_name <chr>, state_legislative_districts_house_district_number <chr>,
## # census_census_year <int>, census_state_fips <chr>, census_county_fips <chr>, census_place_fips <chr>,
## # census_tract_code <chr>, census_block_code <chr>, census_block_group <chr>, postdirectional <chr>
### Test Results
@ -232,7 +222,7 @@ library(testthat)
date()
```
## [1] "Sun Mar 5 14:40:22 2017"
## [1] "Mon Mar 6 07:21:16 2017"
``` r
test_dir("tests/")

16
man/gio_batch_geocode.Rd

@ -4,22 +4,32 @@
\alias{gio_batch_geocode}
\title{Geocode up to 10,000 addresses}
\usage{
gio_batch_geocode(addresses, api_key = gio_auth())
gio_batch_geocode(addresses, fields, api_key = gio_auth())
}
\arguments{
\item{addresses}{character vector of addresses (10K max)}
\item{fields}{vector of additional fields to return with query results. Note that these
count as extra lookups and impact your dailu quota/costs. See \href{https://geocod.io/docs/#fields}{the official documentation}
for more information on costs/pricing. Can be \code{cd}, \code{cd113}, \code{cd114}, or \code{cd115} for
current or historical Congressional districts (U.S.); \code{stateleg} for State Legislative District (House & Senate, U.S.);
\code{school} forSchool District (elementary/secondary or unified, U.S.); \code{census} for
Census Block/Tract & FIPS codes (U.S.) or \code{timezone} for timezone.}
\item{api_key}{\code{geocod.io} API key}
}
\description{
Geocode up to 10,000 addresses
}
\examples{
gio_batch_geocode(c(
addresses <- c(
"1109 N Highland St, Arlington VA",
"525 University Ave, Toronto, ON, Canada",
"4410 S Highway 17 92, Casselberry FL",
"15000 NE 24th Street, Redmond WA",
"17015 Walnut Grove Drive, Morgan Hill CA"
))
)
gio_batch_geocode(addresses)
gio_batch_geocode(addresses, fields=c("cd", "stateleg"))
}

10
man/gio_batch_reverse.Rd

@ -4,11 +4,18 @@
\alias{gio_batch_reverse}
\title{Reverse geocode up to 10,000 coordinates}
\usage{
gio_batch_reverse(coordinates, api_key = gio_auth())
gio_batch_reverse(coordinates, fields, api_key = gio_auth())
}
\arguments{
\item{coordinates}{data frame of coordinates with \code{lat} and \code{lon} columns}
\item{fields}{vector of additional fields to return with query results. Note that these
count as extra lookups and impact your dailu quota/costs. See \href{https://geocod.io/docs/#fields}{the official documentation}
for more information on costs/pricing. Can be \code{cd}, \code{cd113}, \code{cd114}, or \code{cd115} for
current or historical Congressional districts (U.S.); \code{stateleg} for State Legislative District (House & Senate, U.S.);
\code{school} forSchool District (elementary/secondary or unified, U.S.); \code{census} for
Census Block/Tract & FIPS codes (U.S.) or \code{timezone} for timezone.}
\item{api_key}{\code{geocod.io} API key}
}
\description{
@ -20,4 +27,5 @@ data.frame(
lon = c(-77.9658000, -96.6303900, -117.8362320, -80.6784760)
) -> to_code
gio_batch_reverse(to_code)
gio_batch_reverse(to_code, fields=c("census", "stateleg"))
}

14
man/gio_geocode.Rd

@ -4,16 +4,26 @@
\alias{gio_geocode}
\title{Geocode a single address}
\usage{
gio_geocode(address, api_key = gio_auth())
gio_geocode(address, fields, api_key = gio_auth())
}
\arguments{
\item{address}{address to geocode}
\item{fields}{vector of additional fields to return with query results. Note that these
count as extra lookups and impact your dailu quota/costs. See \href{https://geocod.io/docs/#fields}{the official documentation}
for more information on costs/pricing. Can be \code{cd}, \code{cd113}, \code{cd114}, or \code{cd115} for
current or historical Congressional districts (U.S.); \code{stateleg} for State Legislative District (House & Senate, U.S.);
\code{school} forSchool District (elementary/secondary or unified, U.S.); \code{census} for
Census Block/Tract & FIPS codes (U.S.) or \code{timezone} for timezone.}
\item{api_key}{\code{geocod.io} API key}
}
\description{
Geocode a single address
}
\examples{
gio_geocode("1109 N Highland St, Arlington, VA")
\dontrun{
gio_geocode("1109 N Highland St, Arlcdceington, VA")
gio_geocode("1109 N Highland St, Arlington, VA", fields=c("cd", "stateleg"))
}
}

9
man/gio_geocode_components.Rd

@ -4,12 +4,19 @@
\alias{gio_geocode_components}
\title{Geocode a single address}
\usage{
gio_geocode_components(street, city, state, postal_code, country,
gio_geocode_components(street, city, state, postal_code, country, fields,
api_key = gio_auth())
}
\arguments{
\item{street, city, state, postal_code, country}{address components}
\item{fields}{vector of additional fields to return with query results. Note that these
count as extra lookups and impact your dailu quota/costs. See \href{https://geocod.io/docs/#fields}{the official documentation}
for more information on costs/pricing. Can be \code{cd}, \code{cd113}, \code{cd114}, or \code{cd115} for
current or historical Congressional districts (U.S.); \code{stateleg} for State Legislative District (House & Senate, U.S.);
\code{school} forSchool District (elementary/secondary or unified, U.S.); \code{census} for
Census Block/Tract & FIPS codes (U.S.) or \code{timezone} for timezone.}
\item{api_key}{\code{geocod.io} API key}
}
\description{

10
man/gio_reverse.Rd

@ -4,11 +4,18 @@
\alias{gio_reverse}
\title{Reverse geocode a single lat/lon pair}
\usage{
gio_reverse(lat, lon, api_key = gio_auth())
gio_reverse(lat, lon, fields, api_key = gio_auth())
}
\arguments{
\item{lat, lon}{lat/lon pair to reverse geocode}
\item{fields}{vector of additional fields to return with query results. Note that these
count as extra lookups and impact your dailu quota/costs. See \href{https://geocod.io/docs/#fields}{the official documentation}
for more information on costs/pricing. Can be \code{cd}, \code{cd113}, \code{cd114}, or \code{cd115} for
current or historical Congressional districts (U.S.); \code{stateleg} for State Legislative District (House & Senate, U.S.);
\code{school} forSchool District (elementary/secondary or unified, U.S.); \code{census} for
Census Block/Tract & FIPS codes (U.S.) or \code{timezone} for timezone.}
\item{api_key}{\code{geocod.io} API key}
}
\description{
@ -16,4 +23,5 @@ Reverse geocode a single lat/lon pair
}
\examples{
gio_reverse(38.9002898, -76.9990361)
gio_reverse(38.9002898, -76.9990361, fields=c("census", "stateleg"))
}

Loading…
Cancel
Save