[1] "sf" "data.frame"
Rows: 3,221
Columns: 13
$ STATEFP <chr> "05", "08", "26", "28", "38", "39", "21", "02", "48", "40",…
$ COUNTYFP <chr> "121", "069", "105", "153", "075", "125", "095", "230", "06…
$ COUNTYNS <chr> "00069178", "00198150", "01622995", "00695797", "01034229",…
$ AFFGEOID <chr> "0500000US05121", "0500000US08069", "0500000US26105", "0500…
$ GEOID <chr> "05121", "08069", "26105", "28153", "38075", "39125", "2109…
$ NAME <chr> "Randolph", "Larimer", "Mason", "Wayne", "Renville", "Pauld…
$ NAMELSAD <chr> "Randolph County", "Larimer County", "Mason County", "Wayne…
$ STUSPS <chr> "AR", "CO", "MI", "MS", "ND", "OH", "KY", "AK", "TX", "OK",…
$ STATE_NAME <chr> "Arkansas", "Colorado", "Michigan", "Mississippi", "North D…
$ LSAD <chr> "06", "06", "06", "06", "06", "06", "06", "12", "06", "06",…
$ ALAND <dbl> 1688445990, 6723014102, 1281963206, 2099745602, 2272050275,…
$ AWATER <dbl> 10370823, 98984559, 1935616622, 7255476, 40658499, 6245396,…
$ geometry <MULTIPOLYGON [°]> MULTIPOLYGON (((-91.40492 3..., MULTIPOLYGON (…
Make numeric versions of STATEFP and GEOID. Eliminate Alaska, Hawaii and other islands.
GEOGCS["NAD83",
DATUM["North_American_Datum_1983",
SPHEROID["GRS 1980",6378137,298.257222101]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AXIS["Latitude",NORTH],
AXIS["Longitude",EAST],
AUTHORITY["EPSG","4269"]]
The same information could be obtained by a simple call to st_crs(). The output is a little harder to read.
Coordinate Reference System:
User input: NAD83
wkt:
GEOGCRS["NAD83",
DATUM["North American Datum 1983",
ELLIPSOID["GRS 1980",6378137,298.257222101,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["latitude",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["longitude",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4269]]
The most important thing is the EPSG code.
Give prism access to the current working directory.
First, download the 30-year normals for annual precipitation from prism.
|
| | 0%
|
|======================================================================| 100%
Next, download the precipitation data for all months of 2018.
|
| | 0%
|
|====== | 8%
|
|============ | 17%
|
|================== | 25%
|
|======================= | 33%
|
|============================= | 42%
|
|=================================== | 50%
|
|========================================= | 58%
|
|=============================================== | 67%
|
|==================================================== | 75%
|
|========================================================== | 83%
|
|================================================================ | 92%
|
|======================================================================| 100%
Note that resolution for the monthly data is not specified. Only 4km is available.
Get a list of all the downloaded files and store it in prism_files.
[1] "PRISM_ppt_30yr_normal_4kmM4_annual_bil"
[2] "PRISM_ppt_stable_4kmM3_201801_bil"
[3] "PRISM_ppt_stable_4kmM3_201802_bil"
[4] "PRISM_ppt_stable_4kmM3_201803_bil"
[5] "PRISM_ppt_stable_4kmM3_201804_bil"
[6] "PRISM_ppt_stable_4kmM3_201805_bil"
[7] "PRISM_ppt_stable_4kmM3_201806_bil"
[8] "PRISM_ppt_stable_4kmM3_201807_bil"
[9] "PRISM_ppt_stable_4kmM3_201808_bil"
[10] "PRISM_ppt_stable_4kmM3_201809_bil"
[11] "PRISM_ppt_stable_4kmM3_201810_bil"
[12] "PRISM_ppt_stable_4kmM3_201811_bil"
[13] "PRISM_ppt_stable_4kmM3_201812_bil"
chr [1:13] "PRISM_ppt_30yr_normal_4kmM4_annual_bil" ...
Define the paths to the prism data.
What is prism_paths?
chr [1:13] "./PRISM_ppt_30yr_normal_4kmM4_annual_bil/PRISM_ppt_30yr_normal_4kmM4_annual_bil.bil" ...
It’s just a vector of character strings. Look at the first item.
[1] "./PRISM_ppt_30yr_normal_4kmM4_annual_bil/PRISM_ppt_30yr_normal_4kmM4_annual_bil.bil"
Convert the prism data to rasters using the rast() function from terrs.
What are these things?
class : SpatRaster
dimensions : 621, 1405, 1 (nrow, ncol, nlyr)
resolution : 0.04166667, 0.04166667 (x, y)
extent : -125.0208, -66.47917, 24.0625, 49.9375 (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat NAD83
source : PRISM_ppt_30yr_normal_4kmM4_annual_bil.bil
name : PRISM_ppt_30yr_normal_4kmM4_annual_bil
min value : 46.2574
max value : 5611.1611
S4 class 'SpatRaster' [package "terra"]
[1] "GEOGCRS[\"NAD83\",\n DATUM[\"North American Datum 1983\",\n ELLIPSOID[\"GRS 1980\",6378137,298.257222101,\n LENGTHUNIT[\"metre\",1]],\n ID[\"EPSG\",6269]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"Degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"longitude\",east,\n ORDER[1],\n ANGLEUNIT[\"Degree\",0.0174532925199433]],\n AXIS[\"latitude\",north,\n ORDER[2],\n ANGLEUNIT[\"Degree\",0.0174532925199433]]]"
class : SpatRaster
dimensions : 621, 1405, 12 (nrow, ncol, nlyr)
resolution : 0.04166667, 0.04166667 (x, y)
extent : -125.0208, -66.47917, 24.0625, 49.9375 (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat NAD83
sources : PRISM_ppt_stable_4kmM3_201801_bil.bil
PRISM_ppt_stable_4kmM3_201802_bil.bil
PRISM_ppt_stable_4kmM3_201803_bil.bil
... and 9 more source(s)
names : PRISM~1_bil, PRISM~2_bil, PRISM~3_bil, PRISM~4_bil, PRISM~5_bil, PRISM~6_bil, ...
min values : 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, ...
max values : 1696.978, 799.842, 1058.936, 941.047, 694.387, 535.787, ...
S4 class 'SpatRaster' [package "terra"]