Skip to content

Commit 41b0527

Browse files
Florian MayerFlorian Mayer
authored andcommitted
Improve vignette "spatial", add links
1 parent 099c400 commit 41b0527

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

vignettes/spatial.Rmd

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ If several spatial fields are captured, it is up to the user to choose which
3636
field to use as primary geometry.
3737

3838
The second difficulty is that the parsed data from ODK Central is a plain table
39-
(`tbl_df`) with some columns containing spatial data. WKT is stored in text
40-
columns, GeoJSON is stored in list columns.
39+
(`tbl_df`) in which some columns contain spatial data. WKT is stored in text
40+
columns, GeoJSON is stored in list columns. This format is not recognised as a
41+
standard spatial input format.
4142

4243
```{r, message=FALSE}
4344
library(ruODK)
@@ -91,11 +92,15 @@ longitude, altitude, and accuracy individually e.g. to plot a Leaflet map.
9192

9293
```{r, fig.width=9, fig.height=7}
9394
geo_sf_point <- geo_wkt %>% sf::st_as_sf(wkt="point_location_point_gps")
95+
# Mapview using sf
9496
mapview::mapview(geo_sf_point, col.regions = sf::sf.colors(10))
97+
# GGplot using sf
9598
ggplot2::ggplot() + ggplot2::geom_sf(data = geo_sf_point, ggplot2::aes(fill = device_id))
99+
# Leaflet using sf
96100
leaflet::leaflet(data = geo_sf_point) %>%
97101
leaflet::addTiles() %>%
98102
leaflet::addMarkers(label = ~ device_id, popup = ~ device_id)
103+
# Leflet using extracted coordinate components in tbl_df
99104
leaflet::leaflet(data = geo_wkt) %>%
100105
leaflet::addTiles() %>%
101106
leaflet::addMarkers(
@@ -111,9 +116,13 @@ We use `sf::st_as_sf` on a text column containing a WKT geotrace.
111116

112117
```{r, fig.width=9, fig.height=7}
113118
geo_sf_line <- geo_wkt %>% sf::st_as_sf(wkt="path_location_path_gps")
119+
# Mapview using sf
114120
mapview::mapview(geo_sf_line, col.regions = sf::sf.colors(10))
121+
# GGplot using sf
115122
ggplot2::ggplot() +
116123
ggplot2::geom_sf(data = geo_sf_line, ggplot2::aes(fill = device_id))
124+
# Leaflet using first extracted coordinate compoments from plain tbl_df
125+
# Note this represents the geotrace (line) with a simple point
117126
leaflet::leaflet(data = geo_wkt) %>%
118127
leaflet::addTiles() %>%
119128
leaflet::addMarkers(
@@ -123,19 +132,46 @@ leaflet::leaflet(data = geo_wkt) %>%
123132
popup = ~ device_id)
124133
```
125134

126-
## Map geoshapes
135+
## Map geoshapes (polygons)
127136
Again, we'll use `sf::st_as_sf` but select a WKT geoshape column.
128137

129138
```{r, fig.width=9, fig.height=7}
130139
geo_sf_poly <- geo_wkt %>% sf::st_as_sf(wkt="shape_location_shape_gps")
140+
# Mapview using sf
131141
mapview::mapview(geo_sf_poly, col.regions = sf::sf.colors(10))
142+
# GGplot using sf
132143
ggplot2::ggplot() +
133144
ggplot2::geom_sf(data = geo_sf_poly, ggplot2::aes(fill = device_id))
145+
# Leaflet using first extracted coordinate compoments from plain tbl_df
146+
# Note this represents the geoshape (polygon) with a simple point
134147
leaflet::leaflet(data = geo_wkt) %>%
135148
leaflet::addTiles() %>%
136149
leaflet::addMarkers(
137150
lng = ~ shape_location_shape_gps_longitude,
138151
lat = ~ shape_location_shape_gps_latitude,
139152
label = ~ device_id,
140153
popup = ~ device_id)
141-
```
154+
```
155+
156+
# Outlook
157+
The above examples show how to turn spatial data into an `sf` object, and give
158+
very rudimentary visualisation examples.
159+
160+
See the [sf homepage](https://r-spatial.github.io/sf/) for more
161+
context and examples.
162+
The [sf cheatsheet](https://github.com/rstudio/cheatsheets/blob/master/sf.pdf)
163+
deserves a spatial mention.
164+
165+
There are several other good entry points for all things R and spatial,
166+
including but not limited to:
167+
168+
* The [R Spatial CRAN Task View](https://cran.r-project.org/web/views/Spatial.html)
169+
* The [RSpatial](https://rspatial.org/) website
170+
* [Geospatial data in R and beyond](https://www.maths.lancs.ac.uk/~rowlings/Teaching/UseR2012/)
171+
by [Barry Rowlingson](http://barry.rowlingson.com/)
172+
* [GIS with R](https://www.jessesadler.com/post/gis-with-r-intro/)
173+
by [Jesse Sadler](https://www.jessesadler.com/page/cv/)
174+
175+
The above list of examples and resources is far from comprehensive.
176+
Feel free to [contribute or suggest](https://github.com/ropensci/ruODK/issues)
177+
other working examples for turning data from `ruODK` into spatial formats.

0 commit comments

Comments
 (0)