Skip to content

Commit

Permalink
pkgdown updata
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejohnson51 committed Nov 2, 2019
1 parent 3126620 commit f689fe3
Show file tree
Hide file tree
Showing 568 changed files with 197,437 additions and 51,091 deletions.
Binary file modified .DS_Store
Binary file not shown.
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ Version: 0.1.9000
Authors@R: person(given = "Mike", family = "Johnson", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0002-5288-8350"))
Maintainer: Mike Johnson <[email protected]>
BugReports: https://github.com/mikejohnson51/AOI/issues
Description: A consistent tool kit for forward and reverse geocoding and defining boundaries for spatial analysis.
Description: A consistent tool kit for forward and reverse geocoding and defining boundaries for spatial analysis.
Depends:
R(>= 3.5.0),
leaflet
R(>= 3.5.0)
Imports:
dplyr,
jsonlite,
magrittr,
rvest,
xml2,
sf(>= 0.6-0),
leaflet,
utils
Suggests:
testthat,
covr
License: MIT + file LICENSE
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export(make_sf)
export(modify)
export(revgeocode)
import(leaflet)
importFrom(dplyr,mutate)
importFrom(dplyr,select)
importFrom(jsonlite,fromJSON)
importFrom(magrittr,"%>%")
importFrom(rvest,html_attr)
Expand All @@ -36,4 +38,5 @@ importFrom(sf,st_polygon)
importFrom(sf,st_sfc)
importFrom(sf,st_transform)
importFrom(stats,complete.cases)
importFrom(utils,globalVariables)
importFrom(xml2,read_html)
26 changes: 15 additions & 11 deletions R/check.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @title Generate Leafet map and tool set
#' @title Generate Leafet map and tool set
#' @description Provides a precanned leaflet layout for checking, and refining AOI queries. Useful \code{leaflet} tools allow for the marking of points, measuring of distances, and panning and zooming.
#' @param AOI any spatial object (\code{raster}, \code{sf}, \code{sp}). Can be piped (\%>\%) from \code{\link{getAOI}}. If \code{AOI = NULL}, base map of CONUS will be returned.
#' @param returnMap \code{logical}. If \code{FALSE} (default) the input AOI is returned and the leaflet map printed. If \code{TRUE} the leaflet map is returned and printed.
Expand Down Expand Up @@ -35,18 +35,22 @@ check = function(AOI = NULL, returnMap = FALSE) {
bb = NULL
pts = NULL

if(checkClass(AOI, 'sf')){
AOI = sf::st_transform(AOI, '+proj=longlat +datum=WGS84')
}
orig = AOI

if(checkClass(AOI, 'raster')){
bb = getBoundingBox(AOI) %>% st_transform('+proj=longlat +datum=WGS84')
}
if(!checkClass(AOI, "list")){ AOI = list(AOI = AOI)}

type = NULL

for( i in 1:length(AOI)){

if(checkClass(AOI[[i]], 'sf')){
AOI[[i]] = sf::st_transform(AOI[[i]], '+proj=longlat +datum=WGS84')
}

if(checkClass(AOI[[i]], 'raster')){
bb = getBoundingBox(AOI[[i]]) %>% st_transform('+proj=longlat +datum=WGS84')
}

type[i] = tryCatch({
as.character(unique(st_geometry_type(AOI[[i]])[1]))
}, error = function(e) {
Expand All @@ -63,11 +67,11 @@ check = function(AOI = NULL, returnMap = FALSE) {
}

if("MULTIPOLYGON" %in% type){
bb = AOI[[which(grepl("POLYGON",type))]]
bb = AOI[[which(grepl("MULTIPOLYGON",type))]]
}


m= leaflet() %>%
m = leaflet() %>%
addProviderTiles("Esri.NatGeoWorldMap", group = "Terrain") %>%
addProviderTiles("CartoDB.Positron", group = "Grayscale") %>%
addProviderTiles("Esri.WorldImagery", group = "Imagery") %>%
Expand All @@ -87,7 +91,7 @@ check = function(AOI = NULL, returnMap = FALSE) {
options = layersControlOptions(collapsed = T)
)

if(is.null(AOI)){
if(is.null(orig)){
m = setView(m, lat = 39.311825, lng = -101.275972, zoom = 4)
} else {

Expand All @@ -109,7 +113,7 @@ check = function(AOI = NULL, returnMap = FALSE) {

print(m)

if(returnMap) {return(m)} else {return(AOI)}
if(returnMap) {return(m)} else {return(orig)}

}

30 changes: 20 additions & 10 deletions R/data_AOI.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#' @title USA States
#' @description Dataset containing \code{SpatialPolygons} of USA States. Data is initalized from the USAboundaries and USAboundariesData
#' package, converted to \code{SpatialPolygons}, re-projected and cleaned-up for this package. The primary reason for doing this is to provide
#' a more minimalistic dataset primed for this package and leaflet use.
#' @description Dataset containing polygon representations of USA States.
#' @docType data
#' @format a \code{SpatialPolygonsDataFrame}, 52 observations of 5 variables:
#' @format a simple feature polygon set with 52 observations of 5 variables:
#' \itemize{
#' \item 'statefp' : \code{character} 2-digit Federal Information Processing Standards (FIPS) code
#' \item 'statens' : \code{character} American National Standards Institute (ANSI) code
Expand All @@ -19,9 +17,7 @@
"states"

#' @title USA Counites
#' @description Dataset containing \code{SpatialPolygons} of USA Counties. Data is initalized from the USAboundaries and USAboundariesData
#' package, converted to \code{SpatialPolygons}, re=projected and cleaned-up for this package. The primary reason for doing this to provide
#' a more minimalistic dataset primed for this package and leaflet use.
#' @description Dataset containing polygon representations of USA Counties.
#' @docType data
#' @format a \code{SpatialPolygonsDataFrame}, 3220 observations of 7 variables:
#' \itemize{
Expand All @@ -41,8 +37,7 @@
"counties"

#' @title Simplified World Boundaries
#' @description Dataset containing \code{SpatialPolygons} of World Countries and Regions. Data is initalized from \href{http://thematicmapping.org/downloads/world_borders.php}{thematicmapping.org}
#' package, converted to \code{SpatialPolygons} and reprojected for this package.
#' @description Dataset containing simpified polygons of World Countries and Regions. Data is initalized from \href{http://thematicmapping.org/downloads/world_borders.php}{thematicmapping.org}.
#' @docType data
#' @format a \code{SpatialPolygonsDataFrame}, 246 observations of 11 variables:
#' \itemize{
Expand Down Expand Up @@ -70,7 +65,7 @@
#' @title USA Zipcode Database
#' @description Dataset containing information for USA Zipcodes. Data is initalized from \href{https://www.boutell.com/zipcodes/}{Tom Boutell}
#' @docType data
#' @format a \code{csv}, 246 43191 of 7 variables:
#' @format a \code{data.frame}, 43191 rows of 7 variables:
#' \itemize{
#' \item 'zip' : \code{integer} Zipcode
#' \item 'city' : \code{character} City Name
Expand All @@ -87,3 +82,18 @@
#'}

"zipcodes"



#' @title USA Zipcode Database
#' @description Dataset containing information for USA Zipcodes. Data is initalized from \href{https://www.boutell.com/zipcodes/}{Tom Boutell}
#' @docType data
#' @format a \code{data.frame}, 233 rows 149variables:
#' @source \href{https://www.naturalearthdata.com/downloads/50m-cultural-vectors/50m-admin-0-countries-2/}{Natural Earth}. The data is joined to a working database of the CIA
#' @source \href{https://www.cia.gov/library/publications/the-world-factbook/}{World Factbook}.
#' @examples
#' \dontrun{
#' AOI::countries
#'}

"countries"
34 changes: 15 additions & 19 deletions R/geoCode.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ geocode = function(location = NULL,
zipcode = NULL,
pt = FALSE,
bb = FALSE,
all = FALSE,
full = FALSE) {


Expand All @@ -43,6 +44,7 @@ geocode = function(location = NULL,
failed = zipcode[!zipcode %in% locs$zip]

if(length(failed) > 0){

xx = geocode(location = as.character(failed), full = T)

locs = rbind(locs, data.frame(
Expand All @@ -58,7 +60,7 @@ geocode = function(location = NULL,
rownames(locs) = NULL

} else if (length(location) == 1) {
df = geocodeOSM(location, pt, bb, full)
df = geocodeOSM(location, pt, bb, all, full)
return(df)

} else {
Expand All @@ -75,17 +77,14 @@ geocode = function(location = NULL,
locs$lon = as.numeric(locs$lon)
} else {
locs = data.frame(
location = location,
request = location,
lat = as.numeric(latlon$lat),
lon = as.numeric(latlon$lon)
)
}
}

points = sf::st_as_sf(
x = locs,
coords = c('lon', 'lat'),
crs = AOI::aoiProj)
points = sf::st_as_sf( x = locs, coords = c('lon', 'lat'), crs = AOI::aoiProj)

if(!is.null(zipcode)){
points = suppressMessages(
Expand All @@ -94,21 +93,18 @@ geocode = function(location = NULL,
)
}

if (any(bb, pt)) {

items = list()

if (pt) { items[["pt"]] = points }

if (bb) { items[["bb"]] = getBoundingBox(points) }

return(items)
if(all){
return( list(coords = locs, pt = points, bb = getBoundingBox(points)))
}else if(pt){
return(points)
} else if(bb){
return(getBoundingBox(points))
} else {
return(locs)
}

} else {
}

return(locs)

}
}


9 changes: 5 additions & 4 deletions R/geocode_wiki.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' alt_page("Twin_towers")
#' }

alt_page = function(loc, pts = FALSE){
alt_page = function(loc, pt = FALSE){
tt = xml2::read_html(paste0('https://en.wikipedia.org/w/index.php?search=',
loc,
'&title=Special%3ASearch&go=Go') )
Expand Down Expand Up @@ -41,7 +41,7 @@ alt_page = function(loc, pts = FALSE){
#' @title Geocoding Events
#' @description A wrapper around the Wikipedia API to return geo-coordinates of requested inputs.
#' @param event \code{character}. a term to search for on wikipeida
#' @param pts \code{logical}. If TRUE point geometery is appended to the returned list()
#' @param pt \code{logical}. If TRUE point geometery is appended to the returned list()
#' @return aa data.frame of lat/lon coordinates
#' @export
#' @author Mike Johnson
Expand All @@ -64,7 +64,7 @@ alt_page = function(loc, pts = FALSE){
#'
#' }

geocode_wiki = function(event = NULL, pts = T){
geocode_wiki = function(event = NULL, pt = FALSE){

loc = gsub(" ", "+", event)
u = paste0('https://en.wikipedia.org/w/api.php?action=opensearch&search=',
Expand Down Expand Up @@ -135,10 +135,11 @@ geocode_wiki = function(event = NULL, pts = T){
# if(is.null(df)){
# message("No data found")
# } else{
if(pts){
if(pt){
points = sf::st_as_sf(x = df, coords = c('lon', 'lat'), crs = 4269)
return(points)
} else {
df = cbind(request = loc, df) %>% data.frame()
return(df)
}
#}
Expand Down
32 changes: 13 additions & 19 deletions R/getAOI.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#' @param county \code{character}. County name(s). Requires \code{state} input. Not case senstive. If 'all' then all counties in a state are returned
#' @param clip \code{spatial}. \code{raster}, \code{sf} or a \code{list} object (see details for list parameters)
#' @param km \code{logical}. If \code{TRUE} distances are in kilometers, default is \code{FALSE} with distances in miles
#' @param bb \code{logical}. Only applicable for country, state, and county calls. If \code{TRUE} the bounding geometry is returned, default is \code{FALSE} and returns fiat geometries
#' @param union \code{logical}. If TRUE objects are unioned into a single object
#' @details A \code{clip} unit can be described by just a place name (eg 'UCSB'). In doing so the associated boundaries determined by \code{\link{geocode}} will be returned.
#' To have greater control over the clip unit it can be defined as a list with a minimum of 3 inputs:
Expand Down Expand Up @@ -97,17 +96,21 @@
#' # Get AOI defined by 10 mile2 bounding box using the 'KMART near UCSB' as lower left corner
#' getAOI(clip = list('KMART near UCSB', 10, 10, 'lowerleft'))
#'}
#'
#'
clip = list("National Water Center, AL", 30, 10)

getAOI = function(clip = NULL,
country = NULL,
state = NULL,
county = NULL,
km = FALSE,
bb = FALSE,
union =FALSE) {

stateAbb = AOI::states$state_abbr

stateName = AOI::states$state_name

shp = NULL

#------------------------------------------------------------------------------#
Expand Down Expand Up @@ -142,33 +145,24 @@ getAOI = function(clip = NULL,
# Fiat Boundary Defintion (Exisiting Spatial/Raster Feature or getFiat()) #
#-----------------------------------------------------------------------------------#

# AOI by country
# AOI by fiat

if(!is.null(country)){
shp <- getFiat(country = country)
}

# AOI by state

if (all(is.null(clip), !is.null(state))) {
shp <- getFiat(state = state, county = county, bb = bb)
if (all(is.null(clip), !is.null(state)) | all(is.null(clip), !is.null(country))) {
shp <- getFiat(country = country, state = state, county = county)
}

# AOI by user shapefile

if (checkClass(clip, "Raster")){
shp = getBoundingBox(clip)
shp = sf::st_transform(shp, aoiProj)
}
shp = getBoundingBox(clip) %>% sf::st_transform(shp, aoiProj)
}

if (checkClass(clip, "Spatial")) {
shp = sf::st_transform(sf::st_as_sf(clip), aoiProj)
shp = getBoundingBox(shp)
shp = sf::st_transform(sf::st_as_sf(clip), aoiProj) %>% getBoundingBox(shp)
}

if (checkClass(clip, "sf")) {
shp = sf::st_transform(clip, aoiProj)
shp = getBoundingBox(shp)
shp = sf::st_transform(clip, aoiProj) %>% getBoundingBox(shp)
}

#------------------------------------------------------------------------------#
Expand All @@ -177,7 +171,7 @@ getAOI = function(clip = NULL,

if(is.null(shp)){

fin = defineClip(clip, km = km)
fin <- defineClip(clip, km = km)

shp <- getClip(location = fin$location,
width = fin$w,
Expand Down
4 changes: 3 additions & 1 deletion R/package_AOI.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
#' @docType package
#' @name AOI
#' @import leaflet
#' @importFrom dplyr select mutate
#' @importFrom jsonlite fromJSON
#' @importFrom sf st_as_sf as_Spatial st_bbox st_transform st_sfc st_polygon st_crs st_geometry_type st_buffer
#' @importFrom rvest html_nodes html_text html_attr html_table
#' @importFrom xml2 read_html
#' @importFrom stats complete.cases
#' @importFrom utils globalVariables


utils::globalVariables(c(".data"))

NULL
Loading

0 comments on commit f689fe3

Please sign in to comment.