Skip to content

Commit 6e89a4a

Browse files
committed
Add warning and info CSS blocks
1 parent 170a7d6 commit 6e89a4a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+168
-67
lines changed

01-intro.Rmd

+9-3
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ First load the `sf` library. If you don't have it, install it in your console or
3838
library(sf)
3939
```
4040

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+
```
4244

4345
We'll use the `st_read` function. This also reads GeoJSON, PostGIS databases, and more.
4446

4547
```{r}
4648
ward86 <- st_read("data/ward1986.shp")
4749
```
50+
```{block type="rmdinfo"}
4851
Press tab after typing in `st_read("")` with your cursor in between the quotation marks and you'll get a nice autocomplete feature.
52+
```
4953

5054
Check what projection the data is in:
5155
```{r}
@@ -64,7 +68,9 @@ We need to project the data: but how do we choose what projection we need? This
6468

6569
![](figs/what-projection.png)
6670

71+
```{block type="rmdinfo"}
6772
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+
```
6874

6975
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.
7076
```{r}
@@ -96,15 +102,15 @@ plot(ward86_stateplane)
96102

97103
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.
98104

99-
### Bad projections
100-
105+
```{block type="rmdwarning"}
101106
Keep in mind that there are "bad" projections for your data. For example, if I accidentally chose the Alaska Albers projection for my data...
102107
```{r}
103108
ward86_alaska <- st_transform(ward86, 3338)
104109
plot(ward86_alaska)
105110
```
106111

107112
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.
113+
```
108114
109115
## Links
110116

03-gis-2.Rmd

+16-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
- `st_intersects()`
1414
- `filter()`: picks cases based on their values, from the `dplyr` package.
1515

16+
```{block type="rmdinfo"}
1617
Hint: For each new function we go over, type `?` in front of it in the console to pull up the help page.
18+
```
1719

1820
## Interactive Tutorial
1921

@@ -55,9 +57,10 @@ ggplot(data = centroids) +
5557
geom_sf()
5658
```
5759

60+
```{block type="rmdwarning"}
5861
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, :
6164
polygon edge not found
6265
```
6366

@@ -112,7 +115,10 @@ ggplot() +
112115
geom_sf(data = water_clean, color = "blue")
113116
```
114117

118+
```{block type="rmdwarning"}
115119
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.
120+
```
121+
116122
```{r}
117123
ggplot() +
118124
geom_sf(data = water_clean, color = "blue") +
@@ -127,19 +133,24 @@ intersects <- st_intersects(ward98, water_clean)
127133
str(intersects)
128134
```
129135

136+
```{block type="rmdwarning"}
137+
130138
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+
134142
that probably means that you forgot to project one of your datasets. Check the CRS with both and fix it with `st_transform`.
143+
```
135144

136145
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.
137146

138147
```{r}
139148
water_wards <- filter(ward98, lengths(intersects) > 0)
140149
```
141150

151+
```{block type="rmdwarning"}
142152
Note: Don't forget the `s` in `lengths` like I did during the workshop!
153+
```
143154

144155
```{block, type='learncheck', purl=FALSE}
145156
Challenge
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

docs/figs/info.png

2.62 KB
Loading

docs/figs/warning.png

3.07 KB
Loading

docs/index.html

+13-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
<li class="chapter" data-level="1.3.3" data-path="introduction-to-spatial-data.html"><a href="introduction-to-spatial-data.html#project-your-data"><i class="fa fa-check"></i><b>1.3.3</b> Project your data</a></li>
121121
<li class="chapter" data-level="1.3.4" data-path="introduction-to-spatial-data.html"><a href="introduction-to-spatial-data.html#your-challenge"><i class="fa fa-check"></i><b>1.3.4</b> Your challenge</a></li>
122122
<li class="chapter" data-level="1.3.5" data-path="introduction-to-spatial-data.html"><a href="introduction-to-spatial-data.html#solution"><i class="fa fa-check"></i><b>1.3.5</b> Solution</a></li>
123-
<li class="chapter" data-level="1.3.6" data-path="introduction-to-spatial-data.html"><a href="introduction-to-spatial-data.html#bad-projections"><i class="fa fa-check"></i><b>1.3.6</b> Bad projections</a></li>
124123
</ul></li>
125124
<li class="chapter" data-level="1.4" data-path="introduction-to-spatial-data.html"><a href="introduction-to-spatial-data.html#links"><i class="fa fa-check"></i><b>1.4</b> Links</a></li>
126125
</ul></li>
@@ -242,6 +241,19 @@ <h2>Additional information</h2>
242241
});
243242
</script>
244243

244+
<!-- dynamically load mathjax for compatibility with self-contained -->
245+
<script>
246+
(function () {
247+
var script = document.createElement("script");
248+
script.type = "text/javascript";
249+
var src = "";
250+
if (src === "" || src === "true") src = "https://cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML";
251+
if (location.protocol !== "file:" && /^https?:/.test(src))
252+
src = src.replace(/^https?:/, '');
253+
script.src = src;
254+
document.getElementsByTagName("head")[0].appendChild(script);
255+
})();
256+
</script>
245257
</body>
246258

247259
</html>

docs/introduction-to-spatial-data.html

+37-12
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
<li class="chapter" data-level="1.3.3" data-path="introduction-to-spatial-data.html"><a href="introduction-to-spatial-data.html#project-your-data"><i class="fa fa-check"></i><b>1.3.3</b> Project your data</a></li>
121121
<li class="chapter" data-level="1.3.4" data-path="introduction-to-spatial-data.html"><a href="introduction-to-spatial-data.html#your-challenge"><i class="fa fa-check"></i><b>1.3.4</b> Your challenge</a></li>
122122
<li class="chapter" data-level="1.3.5" data-path="introduction-to-spatial-data.html"><a href="introduction-to-spatial-data.html#solution"><i class="fa fa-check"></i><b>1.3.5</b> Solution</a></li>
123-
<li class="chapter" data-level="1.3.6" data-path="introduction-to-spatial-data.html"><a href="introduction-to-spatial-data.html#bad-projections"><i class="fa fa-check"></i><b>1.3.6</b> Bad projections</a></li>
124123
</ul></li>
125124
<li class="chapter" data-level="1.4" data-path="introduction-to-spatial-data.html"><a href="introduction-to-spatial-data.html#links"><i class="fa fa-check"></i><b>1.4</b> Links</a></li>
126125
</ul></li>
@@ -191,7 +190,11 @@ <h3><span class="header-section-number">1.3.2</span> Import spatial data</h3>
191190
<span class="kw">library</span>(sf)</code></pre></div>
192191
<pre><code>## Warning: package &#39;sf&#39; was built under R version 3.4.4</code></pre>
193192
<pre><code>## Linking to GEOS 3.6.1, GDAL 2.1.3, PROJ 4.9.3</code></pre>
194-
<p>Tip: You can use the keyboard shortcut Ctrl-Enter to run a line of code in R.</p>
193+
<div class="rmdinfo">
194+
<p>
195+
You can use the keyboard shortcut <code>Ctrl-Enter</code> to run a line of code in R.
196+
</p>
197+
</div>
195198
<p>We’ll use the <code>st_read</code> function. This also reads GeoJSON, PostGIS databases, and more.</p>
196199
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">ward86 &lt;-<span class="st"> </span><span class="kw">st_read</span>(<span class="st">&quot;data/ward1986.shp&quot;</span>)</code></pre></div>
197200
<pre><code>## Reading layer `ward1986&#39; from data source `/Users/angela/Desktop/Spatial Data Science/workshop-notes/data/ward1986.shp&#39; using driver `ESRI Shapefile&#39;
@@ -201,7 +204,11 @@ <h3><span class="header-section-number">1.3.2</span> Import spatial data</h3>
201204
## bbox: xmin: -87.9402 ymin: 41.6443 xmax: -87.524 ymax: 42.0231
202205
## epsg (SRID): 4269
203206
## proj4string: +proj=longlat +datum=NAD83 +no_defs</code></pre>
204-
<p>Press tab after typing in <code>st_read(&quot;&quot;)</code> with your cursor in between the quotation marks and you’ll get a nice autocomplete feature.</p>
207+
<div class="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.
210+
</p>
211+
</div>
205212
<p>Check what projection the data is in:</p>
206213
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">st_crs</span>(ward86)</code></pre></div>
207214
<pre><code>## Coordinate Reference System:
@@ -210,7 +217,7 @@ <h3><span class="header-section-number">1.3.2</span> Import spatial data</h3>
210217
<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>
211218
<p>I can still plot the map, but as a good geographic data analyst, I’ll need to project it.</p>
212219
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">plot</span>(ward86)</code></pre></div>
213-
<p><img src="workshop-notes_files/figure-html/unnamed-chunk-4-1.png" width="672" /></p>
220+
<p><img src="workshop-notes_files/figure-html/unnamed-chunk-6-1.png" width="672" /></p>
214221
</div>
215222
<div id="project-your-data" class="section level3">
216223
<h3><span class="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>
219226
<img src="figs/what-projection.png" />
220227

221228
</div>
222-
<p>I generally do a online search to look up the EPSG codes for the projection I want to use, or use <a href="http://spatialreference.org/">spatialreference.org</a>, which has a database for all EPSG codes for projections.</p>
229+
<div class="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 <a href="http://spatialreference.org/">spatialreference.org</a>, which has a database for all EPSG codes for projections.
232+
</p>
233+
</div>
223234
<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>
224235
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">ward86_utm &lt;-<span class="st"> </span><span class="kw">st_transform</span>(ward86, <span class="dv">32616</span>)</code></pre></div>
225236
<p>I check the CRS - yep, looks right!</p>
@@ -230,7 +241,7 @@ <h3><span class="header-section-number">1.3.3</span> Project your data</h3>
230241
<p>Question: what datum is this in? What are the units for this projection?</p>
231242
<p>Plot it:</p>
232243
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">plot</span>(ward86_utm)</code></pre></div>
233-
<p><img src="workshop-notes_files/figure-html/unnamed-chunk-7-1.png" width="672" /></p>
244+
<p><img src="workshop-notes_files/figure-html/unnamed-chunk-10-1.png" width="672" /></p>
234245
</div>
235246
<div id="your-challenge" class="section level3">
236247
<h3><span class="header-section-number">1.3.4</span> Your challenge</h3>
@@ -246,16 +257,17 @@ <h3><span class="header-section-number">1.3.5</span> Solution</h3>
246257
## EPSG: 3435
247258
## proj4string: &quot;+proj=tmerc +lat_0=36.66666666666666 +lon_0=-88.33333333333333 +k=0.9999749999999999 +x_0=300000.0000000001 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs&quot;</code></pre>
248259
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">plot</span>(ward86_stateplane)</code></pre></div>
249-
<p><img src="workshop-notes_files/figure-html/unnamed-chunk-8-1.png" width="672" /></p>
260+
<p><img src="workshop-notes_files/figure-html/unnamed-chunk-11-1.png" width="672" /></p>
250261
<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+
<div class="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>
251266
</div>
252-
<div id="bad-projections" class="section level3">
253-
<h3><span class="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>
255267
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">ward86_alaska &lt;-<span class="st"> </span><span class="kw">st_transform</span>(ward86, <span class="dv">3338</span>)
256268
<span class="kw">plot</span>(ward86_alaska)</code></pre></div>
257-
<p><img src="workshop-notes_files/figure-html/unnamed-chunk-9-1.png" width="672" /></p>
258-
<p>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.</p>
269+
<p><img src="workshop-notes_files/figure-html/unnamed-chunk-13-1.png" width="672" /></p>
270+
<p>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. ```</p>
259271
</div>
260272
</div>
261273
<div id="links" class="section level2">
@@ -320,6 +332,19 @@ <h2><span class="header-section-number">1.4</span> Links</h2>
320332
});
321333
</script>
322334

335+
<!-- dynamically load mathjax for compatibility with self-contained -->
336+
<script>
337+
(function () {
338+
var script = document.createElement("script");
339+
script.type = "text/javascript";
340+
var src = "";
341+
if (src === "" || src === "true") src = "https://cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML";
342+
if (location.protocol !== "file:" && /^https?:/.test(src))
343+
src = src.replace(/^https?:/, '');
344+
script.src = src;
345+
document.getElementsByTagName("head")[0].appendChild(script);
346+
})();
347+
</script>
323348
</body>
324349

325350
</html>

0 commit comments

Comments
 (0)