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
Copy file name to clipboardExpand all lines: 01-intro.Rmd
+9-3
Original file line number
Diff line number
Diff line change
@@ -38,14 +38,18 @@ First load the `sf` library. If you don't have it, install it in your console or
38
38
library(sf)
39
39
```
40
40
41
-
Tip: You can use the keyboard shortcut Ctrl-Enter to run a line of code in R.
41
+
```{block type="rmdinfo"}
42
+
You can use the keyboard shortcut `Ctrl-Enter` to run a line of code in R.
43
+
```
42
44
43
45
We'll use the `st_read` function. This also reads GeoJSON, PostGIS databases, and more.
44
46
45
47
```{r}
46
48
ward86 <- st_read("data/ward1986.shp")
47
49
```
50
+
```{block type="rmdinfo"}
48
51
Press tab after typing in `st_read("")` with your cursor in between the quotation marks and you'll get a nice autocomplete feature.
52
+
```
49
53
50
54
Check what projection the data is in:
51
55
```{r}
@@ -64,7 +68,9 @@ We need to project the data: but how do we choose what projection we need? This
64
68
65
69

66
70
71
+
```{block type="rmdinfo"}
67
72
I generally do a online search to look up the EPSG codes for the projection I want to use, or use [spatialreference.org](http://spatialreference.org/ ), which has a database for all EPSG codes for projections.
73
+
```
68
74
69
75
After I do some sleuthing, I find that the EPSG code I want for UTM Zone 16 is `32616`. I then use `st_transform()` to project the data, and save it as a new `sf` dataframe.
70
76
```{r}
@@ -96,15 +102,15 @@ plot(ward86_stateplane)
96
102
97
103
Note that the `+units=us-ft` part of the proj4string means that any distance calculations you do on the `ward86_stateplane` data will be done in feet.
98
104
99
-
### Bad projections
100
-
105
+
```{block type="rmdwarning"}
101
106
Keep in mind that there are "bad" projections for your data. For example, if I accidentally chose the Alaska Albers projection for my data...
102
107
```{r}
103
108
ward86_alaska <- st_transform(ward86, 3338)
104
109
plot(ward86_alaska)
105
110
```
106
111
107
112
Clearly this projection isn't great for Chicago! But something to keep in mind, if, say, you're making maps of places closer to the poles.
Copy file name to clipboardExpand all lines: 03-gis-2.Rmd
+16-5
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,9 @@
13
13
-`st_intersects()`
14
14
-`filter()`: picks cases based on their values, from the `dplyr` package.
15
15
16
+
```{block type="rmdinfo"}
16
17
Hint: For each new function we go over, type `?` in front of it in the console to pull up the help page.
18
+
```
17
19
18
20
## Interactive Tutorial
19
21
@@ -55,9 +57,10 @@ ggplot(data = centroids) +
55
57
geom_sf()
56
58
```
57
59
60
+
```{block type="rmdwarning"}
58
61
Note: If you keep getting the following error message, try reversing the `geom_sf`s again and/or highlighting/re-running the lines of code multiple times.
59
-
```{r eval=FALSE}
60
-
Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
62
+
63
+
> Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
61
64
polygon edge not found
62
65
```
63
66
@@ -112,7 +115,10 @@ ggplot() +
112
115
geom_sf(data = water_clean, color = "blue")
113
116
```
114
117
118
+
```{block type="rmdwarning"}
115
119
Note that order matters here! ggplot plots in the order that you give your functions to it, so if you reorder the `geom_sf` calls, the wards are mapped after - and on top of! - the rivers.
Note: This is where projection is extremely important. If you get an error message that says:
131
-
```{r eval=FALSE}
132
-
Error: st_crs(x) == st_crs(y) is not TRUE
133
-
```
139
+
140
+
> Error: st_crs(x) == st_crs(y) is not TRUE
141
+
134
142
that probably means that you forgot to project one of your datasets. Check the CRS with both and fix it with `st_transform`.
143
+
```
135
144
136
145
This is a little hairy, so in order to use this reasonably, we combine it with the `filter` command we learned earlier. We are filtering the original data by whether or not it has any water features that intersect with it.
<pre><code>## Reading layer `ward1986' from data source `/Users/angela/Desktop/Spatial Data Science/workshop-notes/data/ward1986.shp' using driver `ESRI Shapefile'
<p>Press tab after typing in <code>st_read("")</code> with your cursor in between the quotation marks and you’ll get a nice autocomplete feature.</p>
207
+
<divclass="rmdinfo">
208
+
<p>
209
+
Press tab after typing in <code>st_read(“”)</code> with your cursor in between the quotation marks and you’ll get a nice autocomplete feature.
<p>Sike, this isn’t projected! You can tell because the proj4string starts with <code>+proj=longlat</code>. You can still plot this, but things will start to get iffy if you try to do distance or area calculations, or plot these ward boundaries with other layers.</p>
211
218
<p>I can still plot the map, but as a good geographic data analyst, I’ll need to project it.</p>
<h3><spanclass="header-section-number">1.3.3</span> Project your data</h3>
@@ -219,7 +226,11 @@ <h3><span class="header-section-number">1.3.3</span> Project your data</h3>
219
226
<imgsrc="figs/what-projection.png" />
220
227
221
228
</div>
222
-
<p>I generally do a online search to look up the EPSG codes for the projection I want to use, or use <ahref="http://spatialreference.org/">spatialreference.org</a>, which has a database for all EPSG codes for projections.</p>
229
+
<divclass="rmdinfo">
230
+
<p>
231
+
I generally do a online search to look up the EPSG codes for the projection I want to use, or use <ahref="http://spatialreference.org/">spatialreference.org</a>, which has a database for all EPSG codes for projections.
232
+
</p>
233
+
</div>
223
234
<p>After I do some sleuthing, I find that the EPSG code I want for UTM Zone 16 is <code>32616</code>. I then use <code>st_transform()</code> to project the data, and save it as a new <code>sf</code> dataframe.</p>
<p>Note that the <code>+units=us-ft</code> part of the proj4string means that any distance calculations you do on the <code>ward86_stateplane</code> data will be done in feet.</p>
262
+
<divclass="rmdwarning">
263
+
<p>
264
+
Keep in mind that there are “bad” projections for your data. For example, if I accidentally chose the Alaska Albers projection for my data…
265
+
</p>
251
266
</div>
252
-
<divid="bad-projections" class="section level3">
253
-
<h3><spanclass="header-section-number">1.3.6</span> Bad projections</h3>
254
-
<p>Keep in mind that there are “bad” projections for your data. For example, if I accidentally chose the Alaska Albers projection for my data…</p>
0 commit comments