Given a set of points (lat lon), get table of EJScreen API results near each
Source:R/ejscreenapi_plus.R
ejscreenapi_plus.Rd
Using EJScreen API without Shiny app interface
Usage
ejscreenapi_plus(
x,
y = NULL,
radius = 3,
unit = "miles",
wkid = 4326,
fips = NULL,
shapefile = NULL,
namestr = "",
report_every_n = 100,
save_when_report = FALSE,
format_report_or_json = "pjson",
on_server_so_dont_save_files = FALSE,
ipurl = "ejscreen.epa.gov",
mapping_for_names = NULL,
usewhichnames = "r",
calculate_ratios = TRUE,
verbose = FALSE,
getstatefromplacename = TRUE
)
Arguments
- x
longitudes; or path/filename to xlsx or csv with lat, lon; or data.frame or data.table with lat,lon
- y
latitudes, or ignored if x was a file or table with lat,lon info.
- radius
circular buffer radius (in miles by default, unless unit changed)
- unit
default is miles
- wkid
do not use. https://epsg.io/4326
- fips
if used instead of lon,lat it should be a character FIPS code vector (counties, tracts, or blockgroups)
- shapefile
not implemented
- namestr
optional text
- report_every_n
default is to provide an update every so often
- save_when_report
default is FALSE but if TRUE it saves work in progress every so often
- format_report_or_json
do not use
- on_server_so_dont_save_files
default is FALSE, but set to TRUE if this is run on a server
- ipurl
change only if different URL has to be used for the EJScreen API
- mapping_for_names
a table that translates between original (as on FTP site), short friendly (useful in coding or analysis), and long complete variable names (for clearer Excel headers). This can be read from a csv file or from data in a package. Not documented here, as format may change.
- usewhichnames
default is to use the short friendly ones?
- calculate_ratios
whether to add columns with ratio of raw score to the US or State average
- verbose
whether to print to console / viewer / plot
- getstatefromplacename
set to FALSE if you need the exact output of API and TRUE if you want to try to extract ST abbrev and statename from the placename field, which is more likely to be correct than the stateAbbr and stateName fields in the API output.
Value
Returns a data.frame of results, one row per buffer (site), one column per indicator,
with over 300 columns.
ejscreenit()
returns that as one element of a list that also has a map and plot.
Details
See ejscreenit()
for more details on this.
ejscreenit()
uses functions below, but returns a list with table, map, plot, etc.
ejscreenapi_plus()
accepts file or table or vectors of point data,
uses ejscreenapi()
to get EJScreen stats,
and then prepends input table and renames columns, to return a table.
ejscreenapi()
gets EJ stats for many points as a data.table of many rows.
ejscreenapi1()
gets EJ stats for 1 point via API, as data.frame of 1 row.
ejscreenRESTbroker()
gets EJ stats for one point as JSON.
It also now drops redundant columns where the same numbers had been returned from API using the normal name and a synonym name, as with TOTALPOP and "totalPop"
See also
ejscreenit()
which also demonstrates a map and a plot,
and accepts filename as input pts. see ejscreenapi()
that
uses ejscreenapi1()
and ejscreenRESTbroker()
Examples
if (FALSE) # see [ejscreenit()] for examples
pts <- data.frame(
siteid = 1:2,
sitename = c("site A", "site B"),
lon = c(-91.132107, -91.09),
lat = c(30.494982, 30.45)
)
# pts <- testpoints_5
myradius <- 1
x <- testoutput_ejscreenapi_plus_5; names(x) <- fixcolnames(names(x), "r", "long")
# x <- ejscreenapi_plus(pts, radius = myradius, usewhichnames = "long")
# x <- ejscreenapi_plus(x = pts$lon, y = pts$lat, radius = myradius, usewhichnames = "long")
# x <- ejscreenapi_plus(pts, radius = myradius, usewhichnames = "long")
## view results
t(x[1, 3:ncol(x)])
DT::datatable(x , escape = FALSE)
names(x) <- fixcolnames(names(x), "long", "r")
boxplots_ratios((calc_ratios_to_avg(x))$ratios_d, wheretext = myradius)
# \dontrun{}