forked from spatialanalysis/workshop-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
02-gis-1.Rmd
53 lines (41 loc) · 1.38 KB
/
02-gis-1.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Single-Dataset GIS Operations
## Learning Objectives
- Become familiar with several common single-dataset GIS operations
- Calculate centroids of polygons
- Create buffers
- Explore additional single-dataset GIS operations
## Functions Learned
- `st_geometry()`
- `st_centroid()`
- `st_buffer()`
- `st_coordinates()`
- `st_bbox()`
## Interactive Tutorial
```{block type="rmdinfo"}
This workshop's script can be found [here](https://github.com/spatialanalysis/workshop-scripts/blob/master/gis-visualization/spring-2019/R/gis-learning.R).
```
## Exercises
- Project 1986 ward data into correct UTM projection
```{r}
library(sf)
ward86 <- st_read("data/ward1986.shp")
ward86 <- st_transform(ward86, 32616)
plot(ward86)
```
- Calculate centroids of wards with `st_centroid`
```{r}
?st_centroid
centroids <- st_centroid(ward86)
plot(st_geometry(centroids), cex = 0.1)
plot(st_geometry(ward86), add = T)
```
```{r}
plot(st_geometry(ward86))
plot(st_geometry(centroids), cex = 0.1, add = T)
```
- Calculate bounding box with `st_bbox`
- Plot centroids, buffered centroids, and wards for each year
## Links
- Geometric unary operations (aka, single dataset operations): https://r-spatial.github.io/sf/reference/geos_unary.html
- sf cheatsheet: https://github.com/rstudio/cheatsheets/blob/master/sf.pdf
- PostGIS cheatsheet (off of which sf is based): http://www.postgis.us/downloads/postgis21_cheatsheet.pdf