grid_auto {geofacet} | R Documentation |
Generate a grid automatically from a country/continent name or a SpatialPolygonsDataFrame or 'sf' polygons
Description
Generate a grid automatically from a country/continent name or a SpatialPolygonsDataFrame or 'sf' polygons
Usage
grid_auto(x, names = NULL, codes = NULL, seed = NULL)
Arguments
x |
A country/continent name, a SpatialPolygonsDataFrame or 'sf' polygons to build a grid for. |
names |
An optional vector of variable names in |
codes |
An optional vector of variable names in |
seed |
An optional random seed sent to |
Details
If a country or continent name is specified for x
, it can be any of the strings found in auto_countries
or auto_states
. In this case, the rnaturalearth package will be searched for the corresponding shapefiles. You can use get_ne_data
to see what these shapefiles look like.
The columns of the @data
component of resulting shapefile (either user-specified or fetched from rnaturalearth) are those that will be available to names
and codes
.
Examples
## Not run:
# auto grid using a name to identify the country
grd <- grid_auto("brazil", seed = 1234)
grid_preview(grd, label = "name")
# open the result up in the grid designer for further refinement
grid_design(grd, label = "name")
# using a custom file (can be GeoJSON or shapefile)
ff <- system.file("extdata", "bay_counties.geojson", package = "geogrid")
bay_shp <- sf::st_read(ff)
grd <- grid_auto(bay_shp, seed = 1) # names are inferred
grid_preview(grd, label = "name_county")
grid_design(grd, label = "code_fipsstco")
# explicitly specify the names and codes variables to use
grd <- grid_auto(bay_shp, seed = 1, names = "county", codes = "fipsstco")
grid_preview(grd, label = "name_county")
grid_preview(grd, label = "code_fipsstco")
## End(Not run)