Skip to content

Commit

Permalink
readme and vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
tlyons253 committed Jan 2, 2025
1 parent 38c50f1 commit d0e66a5
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ knitr::opts_chunk$set(
```
# MDCSpatialData

MDCSpatialdData provides spatial data sets in tabular or other R-compatible forms (sf, terra) for easy access by MDC staff or others. All data objects are projected in NAD83 UTM15N unless otherwise noted. Measurement attriubutes in spatial objects (e.g., sf, terra) may not be based on the projected coordinate system. All tabular data calculations have been performed on spatial data using NAD83 UTM15N.
MDCSpatialData provides spatial data sets in tabular or other R-compatible forms (sf, terra) for easy access by MDC staff or others. All data objects are projected in NAD83 UTM15N unless otherwise noted. Measurement attriubutes in spatial objects (e.g., sf, terra) may not be based on the projected coordinate system. All tabular data calculations have been performed on spatial data using NAD83 UTM15N.

## Installation
You can install the MDChelp from [GitHub](https://github.com/) with:
Expand Down
81 changes: 81 additions & 0 deletions vignettes/Missouri-Spatial-Data.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
title: "Accessing spatial data for Missouri"
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

I am generally trying to avoid including actual spatial data sets (e.g. sf or terra objects) in with the **MDChelp** package to minimize the package size. Still, if there is some spatial data that can be expressed in tabular form and you don't need the explicit geometry information, I can try to add it in.

The only spatial objects included in the package are an sf object call **counties.mo** which is a spatial layer of all Missouri counties, and **state.mo** which is a single polygon of the state border. They are projected in NAD83 UTM 15N. Two NLCD data sets are also included as tabular data. They are the % and total area (square km) of several cover classes in each county. Cover classes are modified from the original data. See the help sections for each data set to see what changes were made.

Most other types of spatial data can either be obtained from outside sources. Two R pacakges that facilitate this are **tigris** and **FedData**. Tigris lets you download sf objects of files from the national TIGER data set, while FedData lets you download spatial data from a variety of sources (NHD, NLCD, NASS, SSUGO, etc.) Your best bet is to look at those reference manuals, but I give a few quick examples here.

### Plotting the Missouri spatial boundaries

This can be done easily with ggplot
```{r,eval=FALSE}
#not run
MDChelp::counties.mo->counties.mo
MDChelp::state.mo->state.mo
ggplot(counties.mo)+
geom_sf()
ggplot(state.mo)+
geom_sf()
```


### Extracting spatial data from **tigris**

```{r,eval=FALSE}
#not run
tigris::counties(state='MO')->counties.mo # census blocks
tigris::blocks(state=29))->blocks.mo
# school district boundaries
# see tigris documentation
tigris::school_districts(state=29)->schools.mo
```

### Extracting spatial data from **FedData**

There are a number of spatial, landcover, and weather data sets you can pull from. Definitley read the reference manual for this package to get a comprehensive idea of what data are available.

```{r,eval=FALSE}
# need a boundary shape. If it's not a rectangle or a square, one will be created internal to the function before extracting the data. The bounding area will be extracted from the min/max X and Y coordinates of the polygon.
data(state.mo,package='MDChelp')
#get NASS Cropland data layer data
FedData::get_cdl(template=state.mo,
label='MO',
year=2023)->cdl.mo
# returns a SpatRaster, a terra raster object class
#get NHD data
FedData::get_nhd(template=state.mo,
label='MO', #for use if writing the data to file vs storing in memory.
nhdplus=TRUE)->nhd.mo
#Returns a list with 5 sf objects: Points,lines, flowlines, areas (streams and lakes), and water bodies.
# get HUC12 data (the only scale available in FedData)
FedData::get_wbd(template=state.mo,label='MO')->huc.mo
#returns a sf object
```

0 comments on commit d0e66a5

Please sign in to comment.