This function returns geometric data for ZIP Code Tabulation
Areas (ZCTAs), which are rough approximations of many (but not all)
USPS ZIP codes. Downloading and processing these data will be heavily
affected by your internet connection, your choice for the cb
argument, and the processing power of your computer (if you select
specific counties).
Usage
zi_get_geometry (year, style = "zcta5", return = "id", class = "sf",
state = NULL, county = NULL, territory = NULL, cb = FALSE,
starts_with = NULL, includes = NULL, excludes = NULL, method,
shift_geo = FALSE)
Arguments
- year
A four-digit numeric scalar for year.
zippeR
currently supports data between 2010 and 2023- style
A character scalar - either
"zcta5"
or"zcta3"
. See Details below.- return
A character scalar; if
"id"
(default), only the five-digit number of each ZCTA (or three-digit ifstyle = "zcta3"
) is returned. This is the only valid option forstyle = "zcta3"
. Forstyle = "zcta5"
, ifreturn = "full"
, all TIGER/Line columns are returned.- class
A character scalar; if
"sf"
(default), asf
object suitable for mapping will be returned. If"tibble"
, an object that omits the geometric data will be returned instead.- state
A character scalar or vector with character state abbreviations (e.x.
"MO"
) or numeric FIPS codes (e.x.29
). ZCTAs that are within the given states (determined based on a combination ofyear
andmethod
) will be returned. See Details below for more information. This argument is optional unless a argument is also specified forcounty
.- county
A character scalar or vector with character GEOIDs (e.x.
"29510"
). ZCTAs that are within the given states (determined based on a combination ofyear
andmethod
) will be returned. See Details below for more information. This argument is optional.- territory
A character scalar or vector with character territory abbreviations (e.x.
"PR"
) or numeric FIPS codes (e.x.72
). ZCTAs that are within the given territories will be returned. By default, all territories are excluded. The five territory abbreviations are:"AS"
(American Samoa),"GU"
(Guam),"MP"
(Northern Mariana Islands),"PR"
(Puerto Rico), and"VI"
(U.S. Virgin Islands).- cb
A logical scalar; if
FALSE
, the most detailed TIGER/Line data will be used forstyle = "zcta5"
. IfTRUE
, a generalized (1:500k) version of the data will be used. The generalized data will download significantly faster, though they show less detail. According to thetigris::zctas()
documentation, the download size ifTRUE
is ~65MB while it is ~500MB ifcb = FALSE
.This argument does not apply to
style = "zcta3"
, which only returns generalized data. It also does not apply ifclass = "tibble"
.- starts_with
A character scalar or vector containing the first two digits of a GEOID or ZCTA3 value to return. It defaults to
NULL
, which will return all ZCTAs in the US. For example, supplying the argumentstarts_with = c("63", "64")
will return only those ZCTAs or ZCTA3s that begin with 63 or 64. If you supply a state or a county, that will limit the data this argument is applied to, potentially leading to missed ZCTAs.- includes
A character scalar or vector containing GEOID's or ZCTA3 values to include when finalizing output. This may be necessary depending on what is identified with the
method
argument.- excludes
A character scalar or vector containing GEOID's or ZCTA3 values to exclude when finalizing output. This may be necessary depending on what is identified with the
method
argument.- method
A character scalar - either
"intersect"
or"centroid"
. See Details below.- shift_geo
A logical scalar; if
TRUE
, Alaska, Hawaii, and Puerto Rico will be re-positioned so that the lie to the southwest of the continental United States. This defaults toFALSE
, and can only be used when states are not listed for thestate
argument. It does not apply ifclass = "tibble"
.
Value
A sf
object with ZCTAs matching the parameters specified above:
either a nationwide file, a specific state or states, or a specific
county or counties.
Details
This function contains options for both the type of ZCTA and,
optionally, for how state and county data are identified. For type,
either five-digit or three-digit ZCTA geometries are available. The
three-digit ZCTAs were created by geoprocessing the five-digit boundaries
for each year, and then applying a modest amount of simplification
(with sf::st_simplify()
) to reduce file size. The source files
are available on GitHub at https://github.com/chris-prener/zcta3.
Since ZCTAs cross state lines, two methods are used to create these
geometry data for years 2012 and beyond for states and all years for counties.
The "intersect"
method will return ZCTAs that border the states or
counties selected. In most cases, this will result in more ZCTAs being
returned than are actually within the states or counties selected.
Conversely, the "centroid"
method will return only ZCTAs whose
centroids (geographical centers) lie within the states or counties named.
In most cases, this will return fewer ZCTAs than actually lie within the
states or counties selected. Users will need to review their data carefully
and will likely need to use the include
and exclude
arguments
to finalize the geographies returned.
For state-level data in 2010 and 2011, the Census Bureau published individual
state files that will be utilized automatically by zippeR
. If
county-level data are requested for these years, the state-specific file
will be used as a base before identifying ZCTAs within counties using
either the "intersect"
or "centroid"
method described above.
Examples
# \donttest{
# five-digit ZCTAs
## download all ZCTAs for 2020 including territories
zi_get_geometry(year = 2020, territory = c("AS", "GU", "MP", "PR", "VI"),
shift_geo = TRUE)
#> ZCTAs can take several minutes to download. To cache the data and avoid re-downloading in future R sessions, set `options(tigris_use_cache = TRUE)`
#> Simple feature collection with 33791 features and 1 field
#> Geometry type: GEOMETRY
#> Dimension: XY
#> Bounding box: xmin: -10425790 ymin: -1690748 xmax: 3407868 ymax: 4935246
#> Projected CRS: USA_Contiguous_Albers_Equal_Area_Conic
#> First 10 features:
#> GEOID geometry
#> 1 00802 MULTIPOLYGON (((3335768 -15...
#> 2 00820 MULTIPOLYGON (((3393616 -16...
#> 3 00830 MULTIPOLYGON (((3363742 -15...
#> 4 00840 MULTIPOLYGON (((3375061 -16...
#> 5 00850 MULTIPOLYGON (((3382113 -16...
#> 6 00851 MULTIPOLYGON (((3384245 -16...
#> 7 01001 MULTIPOLYGON (((1899020 743...
#> 8 01002 MULTIPOLYGON (((1898929 784...
#> 9 01003 MULTIPOLYGON (((1900438 782...
#> 10 01005 MULTIPOLYGON (((1926031 793...
## download all ZCTAs for 2020 excluding territories
zi_get_geometry(year = 2020, shift_geo = TRUE)
#> ZCTAs can take several minutes to download. To cache the data and avoid re-downloading in future R sessions, set `options(tigris_use_cache = TRUE)`
#> Simple feature collection with 33642 features and 1 field
#> Geometry type: GEOMETRY
#> Dimension: XY
#> Bounding box: xmin: -2798838 ymin: -1690748 xmax: 2259829 ymax: 1565791
#> Projected CRS: USA_Contiguous_Albers_Equal_Area_Conic
#> First 10 features:
#> GEOID geometry
#> 1 01001 MULTIPOLYGON (((1899020 743...
#> 2 01002 MULTIPOLYGON (((1898929 784...
#> 3 01003 MULTIPOLYGON (((1900438 782...
#> 4 01005 MULTIPOLYGON (((1926031 793...
#> 5 01007 MULTIPOLYGON (((1906213 780...
#> 6 01008 MULTIPOLYGON (((1862800 756...
#> 7 01009 MULTIPOLYGON (((1919692 767...
#> 8 01010 MULTIPOLYGON (((1927638 762...
#> 9 01011 MULTIPOLYGON (((1862013 772...
#> 10 01012 MULTIPOLYGON (((1872514 778...
## download all ZCTAs in a selection of states, intersects method
zi_get_geometry(year = 2020, state = c("IA", "IL", "MO"), method = "intersect")
#> ZCTAs can take several minutes to download. To cache the data and avoid re-downloading in future R sessions, set `options(tigris_use_cache = TRUE)`
#> Simple feature collection with 3408 features and 1 field
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -96.786 ymin: 35.99568 xmax: -87.46216 ymax: 43.57309
#> Geodetic CRS: NAD83
#> First 10 features:
#> GEOID geometry
#> 1 46311 MULTIPOLYGON (((-87.52617 4...
#> 2 46394 MULTIPOLYGON (((-87.52485 4...
#> 3 50001 MULTIPOLYGON (((-93.51234 4...
#> 4 50002 MULTIPOLYGON (((-94.74428 4...
#> 5 50003 MULTIPOLYGON (((-94.18363 4...
#> 6 50005 MULTIPOLYGON (((-93.1319 42...
#> 7 50006 MULTIPOLYGON (((-93.49958 4...
#> 8 50007 MULTIPOLYGON (((-93.62002 4...
#> 9 50008 MULTIPOLYGON (((-93.55664 4...
#> 10 50009 MULTIPOLYGON (((-93.53621 4...
## download all ZCTAs in a single county - St. Louis City, MO
zi_get_geometry(year = 2020, state = "MO", county = "29510",
method = "intersect")
#> ZCTAs can take several minutes to download. To cache the data and avoid re-downloading in future R sessions, set `options(tigris_use_cache = TRUE)`
#>
|
| | 0%
|
|== | 3%
|
|=== | 5%
|
|===== | 7%
|
|====== | 9%
|
|======== | 11%
|
|========= | 13%
|
|========== | 15%
|
|============ | 17%
|
|============= | 19%
|
|=============== | 21%
|
|================ | 23%
|
|================== | 25%
|
|=================== | 27%
|
|===================== | 29%
|
|====================== | 31%
|
|======================= | 33%
|
|========================= | 35%
|
|========================== | 38%
|
|============================ | 40%
|
|============================= | 42%
|
|=============================== | 44%
|
|================================ | 46%
|
|================================= | 48%
|
|=================================== | 50%
|
|==================================== | 52%
|
|====================================== | 54%
|
|======================================= | 56%
|
|========================================= | 58%
|
|========================================== | 60%
|
|============================================ | 62%
|
|============================================= | 64%
|
|============================================== | 66%
|
|================================================ | 68%
|
|================================================= | 70%
|
|=================================================== | 73%
|
|==================================================== | 75%
|
|====================================================== | 77%
|
|======================================================= | 79%
|
|========================================================= | 81%
|
|========================================================== | 83%
|
|=========================================================== | 85%
|
|============================================================= | 87%
|
|============================================================== | 89%
|
|================================================================ | 91%
|
|================================================================= | 93%
|
|=================================================================== | 95%
|
|==================================================================== | 97%
|
|======================================================================| 99%
|
|======================================================================| 100%
#> Simple feature collection with 37 features and 1 field
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -90.38038 ymin: 38.48517 xmax: -90.0237 ymax: 38.8557
#> Geodetic CRS: NAD83
#> First 10 features:
#> GEOID geometry
#> 1 62040 MULTIPOLYGON (((-90.19593 3...
#> 2 62048 MULTIPOLYGON (((-90.21194 3...
#> 3 62059 MULTIPOLYGON (((-90.18123 3...
#> 4 62090 MULTIPOLYGON (((-90.18637 3...
#> 5 62201 MULTIPOLYGON (((-90.20462 3...
#> 6 62206 MULTIPOLYGON (((-90.24004 3...
#> 7 62240 MULTIPOLYGON (((-90.26406 3...
#> 8 63101 MULTIPOLYGON (((-90.19868 3...
#> 9 63102 MULTIPOLYGON (((-90.20168 3...
#> 10 63103 MULTIPOLYGON (((-90.23665 3...
# three-digit ZCTAs
## download all ZCTAs for 2018 including territories
zi_get_geometry(year = 2018, territory = c("AS", "GU", "MP", "PR", "VI"),
shift_geo = TRUE)
#> ZCTAs can take several minutes to download. To cache the data and avoid re-downloading in future R sessions, set `options(tigris_use_cache = TRUE)`
#>
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 15%
|
|=========== | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|============== | 21%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================= | 24%
|
|================= | 25%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 27%
|
|=================== | 28%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 29%
|
|===================== | 30%
|
|===================== | 31%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 46%
|
|================================= | 47%
|
|================================= | 48%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 50%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================ | 64%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 69%
|
|================================================= | 70%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|=================================================== | 74%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|======================================================== | 81%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 89%
|
|=============================================================== | 90%
|
|=============================================================== | 91%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 99%
|
|======================================================================| 100%
#> Simple feature collection with 33144 features and 1 field
#> Geometry type: GEOMETRY
#> Dimension: XY
#> Bounding box: xmin: -10429050 ymin: -1690748 xmax: 3407868 ymax: 4935246
#> Projected CRS: USA_Contiguous_Albers_Equal_Area_Conic
#> First 10 features:
#> GEOID geometry
#> 1 00801 MULTIPOLYGON (((3343347 -15...
#> 2 00802 MULTIPOLYGON (((3337683 -15...
#> 3 00820 MULTIPOLYGON (((3386376 -16...
#> 4 00823 MULTIPOLYGON (((3389649 -16...
#> 5 00824 MULTIPOLYGON (((3395723 -16...
#> 6 00830 MULTIPOLYGON (((3363742 -15...
#> 7 00831 MULTIPOLYGON (((3364798 -15...
#> 8 00840 MULTIPOLYGON (((3375061 -16...
#> 9 00841 MULTIPOLYGON (((3381042 -16...
#> 10 00850 MULTIPOLYGON (((3383653 -16...
# }