knitr::opts_chunk$set( collapse = TRUE, comment = "#>", out.width = "100%", dev = "jpeg" ) library(dplyr)
library(AOI)
Geocoding is the act of converting a named entity to a spatial representation. AOI
uses the tidygeocoder
package for geocoding and overlays some basic syntax to return optional representations.
The tidygeocoder
package provides a range of services (see ?tidygeocoder::geo mehtods). You are free to chose your own with the method
argument. The default method for the package is arcgis
.
(AOI:::default_method)
The default AOI::geocode
behavior returns adata.frame
with a "request" named after the input geo
, and an x
, y
column along with the {method}_address
and score
.
geocode("Fort Collins") |> glimpse()
The basic return can be converted to a POINT representation by setting pt = TRUE
.
geocode("Fort Collins", pt = TRUE) |> glimpse()
The data will be returned in the crs specified in the function signature. By default, all AOI utilities act on:
This can be changed to meet your application needs:
geocode("Fort Collins", pt = TRUE, crs = 5070) |> glimpse()
AOI::geocode
is setup to take more then one request and all prior arguments apply:
geocode(c("Boulder", "Fort Collins"), pt = TRUE, crs = 5070) |> glimpse()
Setting bbox = TRUE
will return the bounding box representation of the geo
input using the following rules:
geo
is passed AND and extent is returned, the POLYGON
is generatedgeo
objects are passed, the POLYGON representing the extent of all POINT(s) is returnedgeocode("Fort Collins", bbox = TRUE) |> glimpse()
# EPSG:5070 geocode(c("Boulder", "Fort Collins"), bbox = TRUE, crs = 5070) |> aoi_map(returnMap = TRUE)
If you actually do want the extents of multiple inputs, then pass the inputs through lapply
:
lapply(c('Fort Collins', 'Boulder'), FUN = geocode, bbox = TRUE) |> bind_rows() |> aoi_map(returnMap = TRUE)
Setting all = TRUE
will return both the point
and bbox
representation. The bbox
returned will still follow the same rules:
geocode('Fort Collins', all = TRUE) |> aoi_map(returnMap = TRUE) geocode(geo = c('Fort Collins', 'Boulder'), all = TRUE) |> aoi_map(returnMap = TRUE)
Setting xy = TRUE
will return just the XY coordinates of the geocoded point. This is useful for applications shown later:
geocode("Fort Collins", xy = TRUE) geocode(geo = "Fort Collins", xy = TRUE, crs = 5070)
Moving away for just tidygeocdoing, AOI::geocode provides tha
geocode(event = "dday") |> aoi_map(returnMap = TRUE)
geocode(event = "Hurricane Harvey", all = TRUE) |> aoi_map(returnMap = TRUE)
Reverse geocoding is the act of converting a XY location to a named entity. Here we work through an example of a place
# getting an xy input xy = geocode("UCSB", xy = TRUE)
geocode_rev(xy)
geocode_rev(xy, pt = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.