Title: | Tools to Download and Work with USDA Cropscape Data |
---|---|
Description: | Downloads USDA National Agricultural Statistics Service (NASS) cropscape data for a specified state. Utilities for fips, abbreviation, and name conversion are also provided. Full functionality requires an internet connection, but data sets can be cached for later off-line use. |
Authors: | Jonathan Lisic [cre], Lu Chen [aut], Jemma Stachelek [ctb] |
Maintainer: | Jonathan Lisic <[email protected]> |
License: | Unlimited |
Version: | 1.13 |
Built: | 2025-02-16 04:46:21 UTC |
Source: | https://github.com/jlisic/cdltools |
U.S. Census 2010 FIPS Data containing county names, state and county FIPS codes, and state abbreviations.
census2010FIPS
census2010FIPS
A data frame with 3235 rows and 5 variables.
State two letter abbreviation
State FIPS code
County FIPS code
County Name
FIPS class code
https://www2.census.gov/geo/docs/reference/codes/files/national_county.txt
An array of CDL enumerations that contain corn. The corn enumeration contains:
1 - Corn
225 - Double Crop, Winter Wheat and Corn
226 - Double Crop, Oats and Corn
237 - Double Crop, Barley and Corn
241 - Double Crop, Corn and Soybeans
251 - Non-Irrigated Corn
corn
corn
An object of class numeric
of length 6.
https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php
An array of CDL enumerations that contain cotton. The cotton enumeration contains:
2 - Cotton
232 - Double Crop, Lettuce and Cotton
238 - Double Crop, Winter Wheat and Cotton
239 - Double Crop, Soybeans and Cotton
cotton
cotton
An object of class numeric
of length 4.
https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php
createComparableCDL
uses a base index within a raster list, and sets all other
raster images within the list to the same resolution, projection, and extent. The
raster function resample is used to transform raster images, therefore this
function may be quite slow without tuning.
createComparableCDL( rasterList, filenames, baseIndex = 1, progress = "", threads = FALSE )
createComparableCDL( rasterList, filenames, baseIndex = 1, progress = "", threads = FALSE )
rasterList |
A list of raster images. |
filenames |
An array of file names of raster images to coerce into a raster list,
if |
baseIndex |
The index of the raster list element that all other elements will match with respect to resolution, projection and extent (default = 1). |
progress |
A string for the raster progress bar type, default "" is none, "text" provides text output, "window" provides a gui window if available. Not available for terra. |
threads |
(terra only) passes the thread parameter to Terra (default = FALSE). |
A list of raster images matching in extent, resolution, and projection.
Jonathan Lisic, [email protected]
## Not run: # download multiple years of Iowa Data # for raster r <- getCDL('iowa',c(2006,2010)) # resample based on the 2006 r2 <- createComparableCDL(r,baseIndex=1) # for terra (note it will just reload what was already downloaded) r_terra <- getCDL('iowa',c(2006,2010), returnType = 'terra') # resample based on the 2006 r_terra2 <- createComparableCDL(r_terra,baseIndex=1) ## End(Not run)
## Not run: # download multiple years of Iowa Data # for raster r <- getCDL('iowa',c(2006,2010)) # resample based on the 2006 r2 <- createComparableCDL(r,baseIndex=1) # for terra (note it will just reload what was already downloaded) r_terra <- getCDL('iowa',c(2006,2010), returnType = 'terra') # resample based on the 2006 r_terra2 <- createComparableCDL(r_terra,baseIndex=1) ## End(Not run)
An array of CDL enumerations of cultivated land cover. Not all cultivated enumerations have labels as of this time, and are reserved for future land cover classes. The cultivated enumeration contains:
1 - Corn
2 - Cotton
3 - Rice
4 - Sorghum
5 - Soybeans
6 - Sunflower
7 - 7
8 - 8
9 - 9
10 - Peanuts
11 - Tobacco
12 - Sweet Corn
13 - Pop or Ornamental Corn
14 - Mint
15 - 15
16 - 16
17 - 17
18 - 18
19 - 19
20 - 20
21 - Barley
22 - Durum Wheat
23 - Spring Wheat
24 - Winter Wheat
25 - Other Small Grains
26 - Double Crop Winter Wheat and Soybeans
27 - Rye
28 - Oats
29 - Millet
30 - Speltz
31 - Canola
32 - Flaxseed
33 - Safflower
34 - Rape Seed
35 - Mustard
36 - Alfalfa
38 - Camelina
39 - Buckwheat
40 - 40
41 - Sugarbeets
42 - Dry Beans
43 - Potatoes
44 - Other Crops
45 - Sugarcane
46 - Sweet Potatoes
47 - Misc Vegs and Fruits
48 - Watermelons
49 - Onions
50 - Cucumbers
51 - Chick Peas
52 - Lentils
53 - Peas
54 - Tomatoes
55 - Caneberries
56 - Hops
57 - Herbs
58 - Clover or Wildflowers
61 - Fallow or Idle Cropland
66 - Cherries
67 - Peaches
68 - Apples
69 - Grapes
71 - Other Tree Crops
72 - Citrus
73 - 73
74 - Pecans
75 - Almonds
76 - Walnuts
77 - Pears
78 - 78
79 - 79
80 - 80
96 - 96
196 - 196
197 - 197
198 - 198
199 - 199
200 - 200
201 - 201
202 - 202
203 - 203
204 - Pistachios
205 - Triticale
206 - Carrots
207 - Asparagus
208 - Garlic
209 - Cantaloupes
210 - Prunes
211 - Olives
212 - Oranges
213 - Honeydew Melons
214 - Broccoli
215 - 215
216 - Peppers
217 - Pomegranates
218 - Nectarines
219 - Greens
220 - Plums
221 - Strawberries
222 - Squash
223 - Apricots
224 - Vetch
225 - Double Crop Winter Wheat and Corn
226 - Double Crop Oats and Corn
227 - Lettuce
228 - 228
229 - Pumpkins
230 - Double Crop Lettuce and Durum Wheat
231 - Double Crop Lettuce and Cantaloupe
232 - Double Crop Lettuce and Cotton
233 - Double Crop Lettuce and Barley
234 - Double Crop Durum Wheat and Sorghum
235 - Double Crop Barley and Sorghum
236 - Double Crop Winter Wheat and Sorghum
237 - Double Crop Barley and Corn
238 - Double Crop Winter Wheat and Cotton
239 - Double Crop Soybeans and Cotton
240 - Double Crop Soybeans and Oats
241 - Double Crop Corn and Soybeans
242 - Blueberries
243 - Cabbage
244 - Cauliflower
245 - Celery
246 - Radishes
247 - Turnips
248 - Eggplants
249 - Gourds
250 - Cranberries
251 - Non-Irrigated Corn
252 - Non-Irrigated Soybeans
253 - Non-Irrigated Winter Wheat
254 - Double Crop Barley and Soybeans
255 - Non-Irrigated Double Crop Winter Wheat and Soybeans
cultivated
cultivated
An object of class numeric
of length 133.
https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php
An array of CDL enumerations that contain durum wheat. The durum wheat enumeration contains:
22 - Durum Wheat
230 - Double Crop Lettuce and Durum Wheat
234 - Double Crop Durum Wheat and Sorghum
durumWheat
durumWheat
An object of class numeric
of length 3.
https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php
fips
converts U.S. state and county names and abbreviations to and from FIPS codes.
fips(x, to = "FIPS")
fips(x, to = "FIPS")
x |
A vector, data frame or matrix of character strings or numeric FIPS codes. Character input can be the two-letter postal abbreviation, the full name of a state, or a FIPS code in character format. The string is case insensitive. FIPS codes are the only numeric input supported. |
to |
A character string of output type: "FIPS" will return a numeric fips code. "Abbreviation" will return a two letter state abbreviation. "Name" will return the full state name with spaces. The default output is a numeric FIPS code. |
The Federal Information Processing Standard (FIPS) provides a set of standard numeric codes for referring to U.S. states. This function converts between FIPS codes, state two letter abbreviations, and full state names.
County abbreviations are supported for FIPS to name conversion only.
The output type specified by the "to" argument. If no match can be made, the program returns NA.
Jonathan Lisic, [email protected]
fips("ia") fips('northcarolina', to='Abbreviation') fips('North Carolina') fips(44,to='Name') fips("01001",to='Name')
fips("ia") fips('northcarolina', to='Abbreviation') fips('North Carolina') fips(44,to='Name') fips("01001",to='Name')
getCDL
retrieves CDL state raster objects for a set of years.
getCDL( x, year, alternativeUrl, location = tempdir(), https = TRUE, ssl.verifypeer = TRUE, returnType = "raster" )
getCDL( x, year, alternativeUrl, location = tempdir(), https = TRUE, ssl.verifypeer = TRUE, returnType = "raster" )
x |
Is either a two digit state FIPS code, a two letter abbreviation, or a state name. |
year |
A numerical vector. A set of years of CDL data to download. |
alternativeUrl |
An optional string containing an alternative url. |
location |
An optional string containing a folder to store the file. If no folder is given, the R temporary directory will be used. |
https |
Legacy https flag, all traffic uses https, if you need http provide alternative url. |
ssl.verifypeer |
An optional boolean to turn on and off ssl verfication, default is on. |
returnType |
An optional parameter to select to return either 'raster' or 'terra' based raster files. |
A list of CDL raster objects of interested county for a set of years. Note that this is a generic list allowing for rasters with different extents and resolutions.
Jonathan Lisic, [email protected]
Jemma Stachelek, [email protected]
## Not run: # Get data for California, 2013 and 2015 # by FIPS getCDL(6,c(2013,2015)) # Get data for California, 2013 and 2015 with Terra getCDL("California",c(2013,2015), returnType='terra') # Get all the west coast from 2009 to 2016 getCDL(c("CA","OR","WA"),2013:2016) ## End(Not run)
## Not run: # Get data for California, 2013 and 2015 # by FIPS getCDL(6,c(2013,2015)) # Get data for California, 2013 and 2015 with Terra getCDL("California",c(2013,2015), returnType='terra') # Get all the west coast from 2009 to 2016 getCDL(c("CA","OR","WA"),2013:2016) ## End(Not run)
getCDL_bbox
retrieves a CDL raster object within a bounding box for a set of years.
getCDL_bbox( year, bbox, fileName, res, crs = "EPSG:5070", https = TRUE, alternativeUrl, ssl.verifypeer = TRUE, returnType = "raster" )
getCDL_bbox( year, bbox, fileName, res, crs = "EPSG:5070", https = TRUE, alternativeUrl, ssl.verifypeer = TRUE, returnType = "raster" )
year |
A numerical vector. A set of years of CDL data to download. |
bbox |
An array defining a bounding box of length four. Defining the two points that form the box by latitude then longitude, in that order. The furthest north west pair is entered first. |
fileName |
An optional string indicating where the file should be saved to, default is an R tempfile. |
res |
An optional array of length two defining the pixel resolution in meters, default is 30m. |
crs |
An optional string containing the coordinate reference system, default is EPSG:5070 (Albers is EPSG:5070). |
https |
Legacy https, all traffic uses https, if you need http provide alternative url. |
alternativeUrl |
An optional string containing an alternative url. |
ssl.verifypeer |
An optional boolean to turn on and off ssl verfication, default is on. |
returnType |
An optional parameter to select to return either 'raster' or 'terra' based raster files. |
A raster object containing the contents of a bounding box.
Jonathan Lisic, [email protected]
Jemma Stachelek, [email protected]
## Not run: # Get data for California in 2020 bbox <- c(130783,2203171,153923,2217961) resx <- 30 resy <- 30 year <- 2020 crs <- 'epsg:102004' getCDL_bbox(year,bbox,res=c(resx,resy),crs=crs) ## End(Not run)
## Not run: # Get data for California in 2020 bbox <- c(130783,2203171,153923,2217961) resx <- 30 resy <- 30 year <- 2020 crs <- 'epsg:102004' getCDL_bbox(year,bbox,res=c(resx,resy),crs=crs) ## End(Not run)
matchCount
counts distinct pixel pairs for CDL raster images with
same extents and resolution.
matchCount(x, y, m = 256)
matchCount(x, y, m = 256)
x |
A CDL raster image. |
y |
A CDL raster image. |
m |
A bound for the max enumeration of CDL categories. The default is 256. |
A matrix with pixel counts by unique ordered CDL crop pairs in x and y.
Jonathan Lisic, [email protected]
## Not run: z1 <- matrix( rep(c(1,4),8), nrow=4) z2 <- matrix( rep(c(1:4),4), nrow=4) r1 <- raster(z1) r2 <- raster(z2) a <- matchCount(r1,r2) ## End(Not run)
## Not run: z1 <- matrix( rep(c(1,4),8), nrow=4) z2 <- matrix( rep(c(1:4),4), nrow=4) r1 <- raster(z1) r2 <- raster(z2) a <- matchCount(r1,r2) ## End(Not run)
metadata
downloads classification and crop class metadata from the cropscape website.
metadata(state, year, https = TRUE, ssl.verifypeer = TRUE)
metadata(state, year, https = TRUE, ssl.verifypeer = TRUE)
state |
A numeric fips code, a state's two letter abbreviation, or a state name. |
year |
A numeric year. |
https |
Legacy https, all traffic uses https, if you need http provide alternative url. |
ssl.verifypeer |
An optional boolean to turn on and off ssl verfication, default is on. |
Cropscape provides classification and crop class metadata on the Cropland Data Layer. This function fetches this data through scraping cropscape html.
The metadata for the state identified by the state argument. If no match can be made, the program returns NA. The metadata is returned as a list with two elements, overall and class specific metrics, each in dataframes.
Jonathan Lisic, [email protected]
## Not run: metadata("ia", 2007) metadata('North Carolina',2008) metadata(44,2017) ## End(Not run)
## Not run: metadata("ia", 2007) metadata('North Carolina',2008) metadata(44,2017) ## End(Not run)
An array of CDL enumerations that contain the nothing class. The nothing enumeration contains:
0 - Background
nothing
nothing
An object of class numeric
of length 1.
https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php
An array of CDL enumerations that contain pasture. The pasture enumeration contains:
37 - Other Hay/Non Alfalfa
38 - Camelina
39 - Buckwheat
62 - Pasture/Grass
171 - Grassland Herbaceous
pasture
pasture
An object of class numeric
of length 5.
https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php
The proj4 string used for all CDL data. "+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"
projCDL
projCDL
An object of class character
of length 1.
https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php
An array of CDL enumerations that contain soybeans. The soybeans enumeration contains:
5 - Soybeans
26 - Double Crop Winter Wheat and Soybeans
239 - Double Crop Soybeans and Cotton
240 - Double Crop Soybeans and Oats
241 - Double Crop Corn and Soybeans
252 - Non-Irrigated Soybeans
254 - Double Crop Barley and Soybeans
254 - Double Crop Barley and Soybeans
255 - Non-Irrigated Double Crop Winter Wheat and Soybeans
soybeans
soybeans
An object of class numeric
of length 9.
https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php
An array of CDL enumerations that contain spring wheat. The spring wheat enumeration contains:
23 - Spring Wheat
springWheat
springWheat
An object of class numeric
of length 1.
https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php
U.S. Census 2010 State FIPS Data containing names, FIPS codes, and abbreviations.
stateNames
stateNames
An object of class data.frame
with 55 rows and 3 columns.
State two letter abbreviation
State name
State FIPS code
https://www2.census.gov/geo/docs/reference/codes/files/national_county.txt
updateNamesCDL
converts numeric CDL categories to class labels.
updateNamesCDL(y)
updateNamesCDL(y)
y |
A numeric array of integers associated with CDL categories. |
An array of strings labeling each CDL class. If the CDL class is unspecified then the original integer is returned.
Jonathan Lisic, [email protected]
updateNamesCDL(0:255)
updateNamesCDL(0:255)
A list of enumerated CDL classes and class descriptions.
varNamesCDL
varNamesCDL
An object of class character
of length 282.
https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php
An array of CDL enumerations that contain water. The water enumeration contains:
83 - Water
111 - Open Water
water
water
An object of class numeric
of length 2.
https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php
An array of CDL enumerations that contain winter wheat. The winter wheat enumeration contains:
24 - Winter Wheat
26 - Double Crop Winter Wheat and Soybeans
225 - Double Crop Winter Wheat and Corn
236 - Double Crop Winter Wheat and Sorghum
238 - Double Crop Winter Wheat and Cotton
253 - Non-Irrigated Winter Wheat
255 - Non-Irrigated Double Crop Winter Wheat and Soybeans
winterWheat
winterWheat
An object of class numeric
of length 7.
https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php