You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starting with this episode, we will be moving from working with raster
45
-
data to working with vector data. In this episode, we will open and plot point, line and polygon vector data
46
-
stored in shapefile format in R. These data refer to the [NEON Harvard Forest field site](https://www.neonscience.org/field-sites/field-sites-map/HARV), which we have been working with in previous
47
-
episodes. In later episodes, we will learn how to work with raster and
48
-
vector data together and combine them into a single plot.
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
51
+
into a single plot.
49
52
50
53
## Import Shapefiles
51
54
52
-
We will use the `sf` package to work with vector data in R. Notice that the
53
-
`rgdal` package automatically loads when `sf` is loaded. We will also use the
54
-
`raster` package, which has been loaded in previous episodes, so we can explore raster and vector spatial metadata using similar commands. Make sure you have the `sf` library loaded.
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
@@ -66,7 +70,8 @@ The shapefiles that we will import are:
66
70
67
71
The first shapefile that we will open contains the boundary of our study area
68
72
(or our Area Of Interest or AOI, hence the name `aoiBoundary`). To import
69
-
shapefiles we use the `sf` function `st_read()`. `st_read()` requires the file path to the shapefile.
73
+
shapefiles we use the `sf` function `st_read()`. `st_read()` requires the file
74
+
path to the shapefile.
70
75
71
76
Let's import our AOI:
72
77
@@ -80,9 +85,9 @@ aoi_boundary_HARV <- st_read(
80
85
When we import the `HarClip_UTMZ18` shapefile layer into R (as our
81
86
`aoi_boundary_HARV` object), the `st_read()` function automatically stores
82
87
information about the data. We are particularly interested in the geospatial
83
-
metadata, describing the format, CRS, extent, and other components of
84
-
the vector data, and the attributes which describe properties associated
85
-
with each individual vector object.
88
+
metadata, describing the format, CRS, extent, and other components of the
89
+
vector data, and the attributes which describe properties associated with each
90
+
individual vector object.
86
91
87
92
::::::::::::::::::::::::::::::::::::::::: callout
88
93
@@ -101,58 +106,64 @@ Key metadata for all shapefiles include:
101
106
102
107
1.**Object Type:** the class of the imported object.
103
108
2.**Coordinate Reference System (CRS):** the projection of the data.
104
-
3.**Extent:** the spatial extent (i.e. geographic area that the shapefile covers) of
105
-
the shapefile. Note that the spatial extent for a shapefile represents the combined
106
-
extent for all spatial objects in the shapefile.
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.
107
112
108
-
We can view shapefile metadata using the `st_geometry_type()`, `st_crs()` and `st_bbox()` functions. First, let's view the
109
-
geometry type for our AOI shapefile:
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:
110
116
111
117
```{r}
112
118
st_geometry_type(aoi_boundary_HARV)
113
119
```
114
120
115
-
Our `aoi_boundary_HARV` is a polygon object. The 18 levels shown below
116
-
our output list the possible categories of the geometry type.
117
-
Now let's check what CRS this file data is in:
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
123
+
CRS this file data is in:
118
124
119
125
```{r}
120
126
st_crs(aoi_boundary_HARV)
121
127
```
122
128
123
-
Our data in the CRS **UTM zone 18N**. The CRS is critical to
124
-
interpreting the object's extent values as it specifies units. To find
125
-
the extent of our AOI, we can use the `st_bbox()` function:
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
131
+
can use the `st_bbox()` function:
126
132
127
133
```{r}
128
134
st_bbox(aoi_boundary_HARV)
129
135
```
130
136
131
-
The spatial extent of a shapefile or R spatial object represents the geographic "edge" or location that is the furthest north, south east and west. Thus is represents the overall geographic coverage of the spatial object. Image Source: National Ecological Observatory Network (NEON).
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:
Lastly, we can view all of the metadata and attributes for this shapefile object
136
-
by printing it to the screen:
144
+
Lastly, we can view all of the metadata and attributes for this shapefile
145
+
object by printing it to the screen:
137
146
138
147
```{r}
139
148
aoi_boundary_HARV
140
149
```
141
150
142
151
## Spatial Data Attributes
143
152
144
-
We introduced the idea of spatial data attributes in [an earlier lesson](https://datacarpentry.org/organization-geospatial/02-intro-vector-data). Now we will explore
145
-
how to use spatial data attributes stored in our data to plot
146
-
different features.
153
+
We introduced the idea of spatial data attributes in
0 commit comments