Skip to content

Commit 23f4e10

Browse files
authored
Merge pull request #412 from bechandcock/rename-shapefile-from-main
Issue # 312 to update the terms “shapefile”
2 parents f801b08 + 7a54edd commit 23f4e10

6 files changed

+397
-399
lines changed

episodes/06-vector-open-shapefile-in-r.Rmd

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Open and Plot Shapefiles
2+
title: Open and Plot Vector Layers
33
teaching: 20
44
exercises: 10
55
source: Rmd
@@ -12,7 +12,7 @@ source("setup.R")
1212
::::::::::::::::::::::::::::::::::::::: objectives
1313

1414
- Know the difference between point, line, and polygon vector elements.
15-
- Load point, line, and polygon shapefiles into R.
15+
- Load point, line, and polygon vector layers into R.
1616
- Access the attributes of a spatial object in R.
1717

1818
::::::::::::::::::::::::::::::::::::::::::::::::::
@@ -34,44 +34,44 @@ library(sf)
3434

3535
## Things You'll Need To Complete This Episode
3636

37-
See the [lesson homepage](.) for detailed information about the software, data,
38-
and other prerequisites you will need to work through the examples in this
37+
See the [lesson homepage](.) for detailed information about the software, data,
38+
and other prerequisites you will need to work through the examples in this
3939
episode.
4040

4141

4242
::::::::::::::::::::::::::::::::::::::::::::::::::
4343

44-
Starting with this episode, we will be moving from working with raster data to
45-
working with vector data. In this episode, we will open and plot point, line
46-
and polygon vector data stored in shapefile format in R. These data refer to
47-
the
48-
[NEON Harvard Forest field site](https://www.neonscience.org/field-sites/field-sites-map/HARV),
49-
which we have been working with in previous episodes. In later episodes, we
50-
will learn how to work with raster and vector data together and combine them
44+
Starting with this episode, we will be moving from working with raster data to
45+
working with vector data. In this episode, we will open and plot point, line
46+
and polygon vector data loaded from ESRI's `shapefile` format into R. These data refer to
47+
the
48+
[NEON Harvard Forest field site](https://www.neonscience.org/field-sites/field-sites-map/HARV),
49+
which we have been working with in previous episodes. In later episodes, we
50+
will learn how to work with raster and vector data together and combine them
5151
into a single plot.
5252

53-
## Import Shapefiles
53+
## Import Vector Data
5454

55-
We will use the `sf` package to work with vector data in R. We will also use
56-
the `terra` package, which has been loaded in previous episodes, so we can
57-
explore raster and vector spatial metadata using similar commands. Make sure
55+
We will use the `sf` package to work with vector data in R. We will also use
56+
the `terra` package, which has been loaded in previous episodes, so we can
57+
explore raster and vector spatial metadata using similar commands. Make sure
5858
you have the `sf` library loaded.
5959

6060
```{r load-sf, results="hide", eval=FALSE, message=FALSE}
6161
library(sf)
6262
```
6363

64-
The shapefiles that we will import are:
64+
The vector layers that we will import from ESRI's `shapefile` format are:
6565

66-
- A polygon shapefile representing our field site boundary,
67-
- A line shapefile representing roads, and
68-
- A point shapefile representing the location of the [Fisher flux tower](https://www.neonscience.org/data-collection/flux-tower-measurements)
66+
- A polygon vector layer representing our field site boundary,
67+
- A line vector layer representing roads, and
68+
- A point vector layer representing the location of the [Fisher flux tower](https://www.neonscience.org/data-collection/flux-tower-measurements)
6969
located at the [NEON Harvard Forest field site](https://www.neonscience.org/field-sites/field-sites-map/HARV).
7070

71-
The first shapefile that we will open contains the boundary of our study area
71+
The first vector layer that we will open contains the boundary of our study area
7272
(or our Area Of Interest or AOI, hence the name `aoiBoundary`). To import
73-
shapefiles we use the `sf` function `st_read()`. `st_read()` requires the file
74-
path to the shapefile.
73+
a vector layer from an ESRI `shapefile` we use the `sf` function `st_read()`. `st_read()`
74+
requires the file path to the ESRI `shapefile`.
7575

7676
Let's import our AOI:
7777

@@ -80,20 +80,20 @@ aoi_boundary_HARV <- st_read(
8080
"data/NEON-DS-Site-Layout-Files/HARV/HarClip_UTMZ18.shp")
8181
```
8282

83-
## Shapefile Metadata \& Attributes
83+
## Vector Layer Metadata \& Attributes
8484

85-
When we import the `HarClip_UTMZ18` shapefile layer into R (as our
85+
When we import the `HarClip_UTMZ18` vector layer from an ESRI `shapefile` into R (as our
8686
`aoi_boundary_HARV` object), the `st_read()` function automatically stores
8787
information about the data. We are particularly interested in the geospatial
88-
metadata, describing the format, CRS, extent, and other components of the
89-
vector data, and the attributes which describe properties associated with each
88+
metadata, describing the format, CRS, extent, and other components of the
89+
vector data, and the attributes which describe properties associated with each
9090
individual vector object.
9191

9292
::::::::::::::::::::::::::::::::::::::::: callout
9393

9494
## Data Tip
9595

96-
The [Explore and Plot by Shapefile Attributes](07-vector-shapefile-attributes-in-r/)
96+
The [Explore and Plot by Vector Layer Attributes](07-vector-shapefile-attributes-in-r/)
9797
episode provides more information on both metadata and attributes
9898
and using attributes to subset and plot data.
9999

@@ -102,46 +102,46 @@ and using attributes to subset and plot data.
102102

103103
## Spatial Metadata
104104

105-
Key metadata for all shapefiles include:
105+
Key metadata for all vector layers includes:
106106

107107
1. **Object Type:** the class of the imported object.
108108
2. **Coordinate Reference System (CRS):** the projection of the data.
109-
3. **Extent:** the spatial extent (i.e. geographic area that the shapefile
110-
covers) of the shapefile. Note that the spatial extent for a shapefile
111-
represents the combined extent for all spatial objects in the shapefile.
109+
3. **Extent:** the spatial extent (i.e. geographic area that the vector layer
110+
covers) of the data. Note that the spatial extent for a vector layer
111+
represents the combined extent for all individual objects in the vector layer.
112112

113-
We can view shapefile metadata using the `st_geometry_type()`, `st_crs()` and
114-
`st_bbox()` functions. First, let's view the geometry type for our AOI
115-
shapefile:
113+
We can view metadata of a vector layer using the `st_geometry_type()`, `st_crs()` and
114+
`st_bbox()` functions. First, let's view the geometry type for our AOI
115+
vector layer:
116116

117117
```{r}
118118
st_geometry_type(aoi_boundary_HARV)
119119
```
120120

121-
Our `aoi_boundary_HARV` is a polygon object. The 18 levels shown below our
122-
output list the possible categories of the geometry type. Now let's check what
121+
Our `aoi_boundary_HARV` is a polygon spatial object. The 18 levels shown below our
122+
output list the possible categories of the geometry type. Now let's check what
123123
CRS this file data is in:
124124

125125
```{r}
126126
st_crs(aoi_boundary_HARV)
127127
```
128128

129-
Our data in the CRS **UTM zone 18N**. The CRS is critical to interpreting the
130-
object's extent values as it specifies units. To find the extent of our AOI, we
129+
Our data in the CRS **UTM zone 18N**. The CRS is critical to interpreting the
130+
spatial object's extent values as it specifies units. To find the extent of our AOI, we
131131
can use the `st_bbox()` function:
132132

133133
```{r}
134134
st_bbox(aoi_boundary_HARV)
135135
```
136136

137-
The spatial extent of a shapefile or R spatial object represents the geographic
138-
"edge" or location that is the furthest north, south east and west. Thus is
139-
represents the overall geographic coverage of the spatial object. Image Source:
137+
The spatial extent of a vector layer or R spatial object represents the geographic
138+
"edge" or location that is the furthest north, south east and west. Thus it
139+
represents the overall geographic coverage of the spatial object. Image Source:
140140
National Ecological Observatory Network (NEON).
141141

142142
![](fig/dc-spatial-vector/spatial_extent.png){alt='Extent image'}
143143

144-
Lastly, we can view all of the metadata and attributes for this shapefile
144+
Lastly, we can view all of the metadata and attributes for this R spatial
145145
object by printing it to the screen:
146146

147147
```{r}
@@ -150,33 +150,33 @@ aoi_boundary_HARV
150150

151151
## Spatial Data Attributes
152152

153-
We introduced the idea of spatial data attributes in
154-
[an earlier lesson](https://datacarpentry.org/organization-geospatial/02-intro-vector-data).
155-
Now we will explore how to use spatial data attributes stored in our data to
153+
We introduced the idea of spatial data attributes in
154+
[an earlier lesson](https://datacarpentry.org/organization-geospatial/02-intro-vector-data).
155+
Now we will explore how to use spatial data attributes stored in our data to
156156
plot different features.
157157

158-
## Plot a Shapefile
158+
## Plot a vector layer
159159

160-
Next, let's visualize the data in our `sf` object using the `ggplot` package.
161-
Unlike with raster data, we do not need to convert vector data to a dataframe
160+
Next, let's visualize the data in our `sf` object using the `ggplot` package.
161+
Unlike with raster data, we do not need to convert vector data to a dataframe
162162
before plotting with `ggplot`.
163163

164-
We're going to customize our boundary plot by setting the size, color, and fill
165-
for our plot. When plotting `sf` objects with `ggplot2`, you need to use the
164+
We're going to customize our boundary plot by setting the size, color, and fill
165+
for our plot. When plotting `sf` objects with `ggplot2`, you need to use the
166166
`coord_sf()` coordinate system.
167167

168168
```{r plot-shapefile}
169-
ggplot() +
170-
geom_sf(data = aoi_boundary_HARV, size = 3, color = "black", fill = "cyan1") +
171-
ggtitle("AOI Boundary Plot") +
169+
ggplot() +
170+
geom_sf(data = aoi_boundary_HARV, size = 3, color = "black", fill = "cyan1") +
171+
ggtitle("AOI Boundary Plot") +
172172
coord_sf()
173173
```
174174

175175
::::::::::::::::::::::::::::::::::::::: challenge
176176

177-
## Challenge: Import Line and Point Shapefiles
177+
## Challenge: Import Line and Point Vector Layers
178178

179-
Using the steps above, import the HARV\_roads and HARVtower\_UTM18N layers into
179+
Using the steps above, import the HARV\_roads and HARVtower\_UTM18N vector layers into
180180
R. Call the HARV\_roads object `lines_HARV` and the HARVtower\_UTM18N
181181
`point_HARV`.
182182

@@ -217,8 +217,8 @@ st_crs(point_HARV)
217217
st_bbox(point_HARV)
218218
```
219219

220-
To see the number of objects in each file, we can look at the output from when
221-
we read these objects into R. `lines_HARV` contains 13 features (all lines) and
220+
To see the number of objects in each file, we can look at the output from when
221+
we read these objects into R. `lines_HARV` contains 13 features (all lines) and
222222
`point_HARV` contains only one point.
223223

224224

@@ -231,9 +231,9 @@ we read these objects into R. `lines_HARV` contains 13 features (all lines) and
231231

232232
:::::::::::::::::::::::::::::::::::::::: keypoints
233233

234-
- Shapefile metadata include geometry type, CRS, and extent.
234+
- Metadata for vector layers include geometry type, CRS, and extent.
235235
- Load spatial objects into R with the `st_read()` function.
236-
- Spatial objects can be plotted directly with `ggplot` using the `geom_sf()`
236+
- Spatial objects can be plotted directly with `ggplot` using the `geom_sf()`
237237
function. No need to convert to a dataframe.
238238

239239
::::::::::::::::::::::::::::::::::::::::::::::::::

0 commit comments

Comments
 (0)