get_areas_near_coordinates | R Documentation |
Returns a tibble
containing the census areas whose
centers of population are closest to some user-specified center. To specify
the center, the user can manually enter longitude/latitude coordinates or use
the helper function lon_lat_from_area()
to automatically grab the
longitude/latitude coordinates of the center of population of an area. The
cutoff point for how many areas will be return depends on the function used.
areas_in_radius(
geography = c("state", "county", "tract", "block group"),
center = lon_lat_from_area(state = "DC"),
radius = 5,
units = "miles",
measure_from = "center of population",
year = 2020,
distance_fun = geosphere::distVincentyEllipsoid,
batch_size = 50L
)
closest_n_areas(
geography = c("state", "county", "tract", "block group"),
center = lon_lat_from_area(state = "DC"),
n = 50,
measure_from = "center of population",
year = 2020,
distance_fun = geosphere::distVincentyEllipsoid,
units = NULL,
batch_size = 50L
)
closest_population(
geography = c("state", "county", "tract", "block group"),
center = lon_lat_from_area(state = "DC"),
population = 1e+06,
measure_from = "center of population",
year = 2020,
distance_fun = geosphere::distVincentyEllipsoid,
units = NULL,
batch_size = 50L
)
geography |
The type of census areas that the resulting table will
contain. One of |
center |
The longitude/latitude coordinates of the center of the circle.
A double vector of length 2 whose elements are finite numbers. Passed to
the The first element is the longitude coordinate (positive for west, negative for east). The second element is the latitude coordinate (positive for north, negative for south). The convenience function Defaults to the center of population of the District of Columbia according to the 2020 decennial census. |
radius |
A single, non-negative number specifying the radius of the circle. Defaults to 5. |
units |
A single string specifying the units of the resulting For |
measure_from |
Currently can only be |
year |
Must be 2020, 2010, or 2000. Defaults to 2020. |
distance_fun |
Passed to the |
batch_size |
The number of distances calculated in each iterative call
to |
n |
A single positive integer specifying how many of the areas closest
to |
population |
A single positive integer specifying the target total population of the areas returned. See Details. |
areas_in_radius()
returns all areas whose centers of population are within
the user-specified radius
around center
.
closest_n_areas()
returns the top n
areas whose centers of population are
closest areas to center
.
Conceptually, closest_population()
sequentially gathers the next closest
area to center
until the total population of the areas meets or exceeds
population
.
Distances are determined with geosphere::distm()
.
Requires the packages USpopcenters
and geosphere
to be installed.
Requires the units
to be installed unless units = NULL
.
Centers of population are based on the decennial census data. Only states,
counties, tracts, and block groups are currently supported. See the
documentation of the USpopcenters
package and
https://www.census.gov/geographies/reference-files/time-series/geo/centers-population.html
for more information.
A tibble
with each of the columns found in the
corresponding USpopcenters
table, with two columns appended:
geoid
- all FIPS code columns combined with paste0()
.
distance
- the number of units
the area's LONGITUDE
/LATITUDE
center
of population is away from the coordinates given in center
.
lon_lat_from_area()
if (requireNamespace("USpopcenters", quietly = TRUE) &&
requireNamespace("geosphere", quietly = TRUE)) {
# All states whose centers of population are within 300 kilometers of the
# center of population of New York County, New York (i.e, Manhattan):
areas_in_radius(
geography = "state",
center = lon_lat_from_area(state = "NY", county = "New York"),
radius = 300,
units = "km"
)
# The four census tracts whose centers of population are closest to the
# Four Corners (distance column is in meters due to setting units = NULL):
closest_n_areas("tract", center = c(-109.0452, 36.9991), n = 4, units = NULL)
# The counties closest to center of population of Kauai County, Hawaii whose
# total population reaches 3 million people:
closest_population(
geography = "county",
center = lon_lat_from_area("15007"),
population = 3e6,
units = "barleycorns"
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.