Package 'cdlTools'

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

Help Index


U.S. Census 2010 FIPS Data

Description

U.S. Census 2010 FIPS Data containing county names, state and county FIPS codes, and state abbreviations.

Usage

census2010FIPS

Format

A data frame with 3235 rows and 5 variables.

State

State two letter abbreviation

State.ANSI

State FIPS code

County.ANSI

County FIPS code

County.Name

County Name

ANSI.Cl

FIPS class code

Source

https://www2.census.gov/geo/docs/reference/codes/files/national_county.txt


CDL corn classes

Description

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

Usage

corn

Format

An object of class numeric of length 6.

Source

https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php


CDL cotton classes

Description

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

Usage

cotton

Format

An object of class numeric of length 4.

Source

https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php


Create comparable raster images

Description

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.

Usage

createComparableCDL(
  rasterList,
  filenames,
  baseIndex = 1,
  progress = "",
  threads = FALSE
)

Arguments

rasterList

A list of raster images.

filenames

An array of file names of raster images to coerce into a raster list, if rasterList is not provided.

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).

Value

A list of raster images matching in extent, resolution, and projection.

Author(s)

Jonathan Lisic, [email protected]

Examples

## 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)

CDL cultivated classes

Description

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

Usage

cultivated

Format

An object of class numeric of length 133.

Source

https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php


CDL durum wheat classes

Description

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

Usage

durumWheat

Format

An object of class numeric of length 3.

Source

https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php


FIPS code conversion function.

Description

fips converts U.S. state and county names and abbreviations to and from FIPS codes.

Usage

fips(x, to = "FIPS")

Arguments

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.

Details

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.

Value

The output type specified by the "to" argument. If no match can be made, the program returns NA.

Author(s)

Jonathan Lisic, [email protected]

Examples

fips("ia")
fips('northcarolina', to='Abbreviation')
fips('North Carolina')
fips(44,to='Name')
fips("01001",to='Name')

Get CDL raster data

Description

getCDL retrieves CDL state raster objects for a set of years.

Usage

getCDL(
  x,
  year,
  alternativeUrl,
  location = tempdir(),
  https = TRUE,
  ssl.verifypeer = TRUE,
  returnType = "raster"
)

Arguments

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.

Value

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.

Author(s)

Jonathan Lisic, [email protected]

Jemma Stachelek, [email protected]

Examples

## 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)

Get CDL raster data for a bounding box

Description

getCDL_bbox retrieves a CDL raster object within a bounding box for a set of years.

Usage

getCDL_bbox(
  year,
  bbox,
  fileName,
  res,
  crs = "EPSG:5070",
  https = TRUE,
  alternativeUrl,
  ssl.verifypeer = TRUE,
  returnType = "raster"
)

Arguments

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.

Value

A raster object containing the contents of a bounding box.

Author(s)

Jonathan Lisic, [email protected]

Jemma Stachelek, [email protected]

Examples

## 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)

Counts distinct pixel pairs in CDL raster images

Description

matchCount counts distinct pixel pairs for CDL raster images with same extents and resolution.

Usage

matchCount(x, y, m = 256)

Arguments

x

A CDL raster image.

y

A CDL raster image.

m

A bound for the max enumeration of CDL categories. The default is 256.

Value

A matrix with pixel counts by unique ordered CDL crop pairs in x and y.

Author(s)

Jonathan Lisic, [email protected]

Examples

## 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)

CDL metadata.

Description

metadata downloads classification and crop class metadata from the cropscape website.

Usage

metadata(state, year, https = TRUE, ssl.verifypeer = TRUE)

Arguments

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.

Details

Cropscape provides classification and crop class metadata on the Cropland Data Layer. This function fetches this data through scraping cropscape html.

Value

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.

Author(s)

Jonathan Lisic, [email protected]

Examples

## Not run: 
metadata("ia", 2007)
metadata('North Carolina',2008)
metadata(44,2017)

## End(Not run)

CDL nothing class

Description

An array of CDL enumerations that contain the nothing class. The nothing enumeration contains:

  • 0 - Background

Usage

nothing

Format

An object of class numeric of length 1.

Source

https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php


CDL pasture classes

Description

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

Usage

pasture

Format

An object of class numeric of length 5.

Source

https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php


The default projection of CDL data

Description

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"

Usage

projCDL

Format

An object of class character of length 1.

Source

https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php


CDL soybeans classes

Description

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

Usage

soybeans

Format

An object of class numeric of length 9.

Source

https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php


CDL spring wheat classes

Description

An array of CDL enumerations that contain spring wheat. The spring wheat enumeration contains:

  • 23 - Spring Wheat

Usage

springWheat

Format

An object of class numeric of length 1.

Source

https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php


U.S. Census 2010 State FIPS Data

Description

U.S. Census 2010 State FIPS Data containing names, FIPS codes, and abbreviations.

Usage

stateNames

Format

An object of class data.frame with 55 rows and 3 columns.

Details

STATE

State two letter abbreviation

STATENAME

State name

STATEFP

State FIPS code

Source

https://www2.census.gov/geo/docs/reference/codes/files/national_county.txt


Label CDL classes.

Description

updateNamesCDL converts numeric CDL categories to class labels.

Usage

updateNamesCDL(y)

Arguments

y

A numeric array of integers associated with CDL categories.

Value

An array of strings labeling each CDL class. If the CDL class is unspecified then the original integer is returned.

Author(s)

Jonathan Lisic, [email protected]

Examples

updateNamesCDL(0:255)

Enumerated CDL classes

Description

A list of enumerated CDL classes and class descriptions.

Usage

varNamesCDL

Format

An object of class character of length 282.

Source

https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php


CDL water classes

Description

An array of CDL enumerations that contain water. The water enumeration contains:

  • 83 - Water

  • 111 - Open Water

Usage

water

Format

An object of class numeric of length 2.

Source

https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php


CDL winter wheat classes

Description

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

Usage

winterWheat

Format

An object of class numeric of length 7.

Source

https://www.nass.usda.gov/Research_and_Science/Cropland/metadata/meta.php