@@ -36,8 +36,9 @@ If several spatial fields are captured, it is up to the user to choose which
36
36
field to use as primary geometry.
37
37
38
38
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.
41
42
42
43
``` {r, message=FALSE}
43
44
library(ruODK)
@@ -91,11 +92,15 @@ longitude, altitude, and accuracy individually e.g. to plot a Leaflet map.
91
92
92
93
``` {r, fig.width=9, fig.height=7}
93
94
geo_sf_point <- geo_wkt %>% sf::st_as_sf(wkt="point_location_point_gps")
95
+ # Mapview using sf
94
96
mapview::mapview(geo_sf_point, col.regions = sf::sf.colors(10))
97
+ # GGplot using sf
95
98
ggplot2::ggplot() + ggplot2::geom_sf(data = geo_sf_point, ggplot2::aes(fill = device_id))
99
+ # Leaflet using sf
96
100
leaflet::leaflet(data = geo_sf_point) %>%
97
101
leaflet::addTiles() %>%
98
102
leaflet::addMarkers(label = ~ device_id, popup = ~ device_id)
103
+ # Leflet using extracted coordinate components in tbl_df
99
104
leaflet::leaflet(data = geo_wkt) %>%
100
105
leaflet::addTiles() %>%
101
106
leaflet::addMarkers(
@@ -111,9 +116,13 @@ We use `sf::st_as_sf` on a text column containing a WKT geotrace.
111
116
112
117
``` {r, fig.width=9, fig.height=7}
113
118
geo_sf_line <- geo_wkt %>% sf::st_as_sf(wkt="path_location_path_gps")
119
+ # Mapview using sf
114
120
mapview::mapview(geo_sf_line, col.regions = sf::sf.colors(10))
121
+ # GGplot using sf
115
122
ggplot2::ggplot() +
116
123
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
117
126
leaflet::leaflet(data = geo_wkt) %>%
118
127
leaflet::addTiles() %>%
119
128
leaflet::addMarkers(
@@ -123,19 +132,46 @@ leaflet::leaflet(data = geo_wkt) %>%
123
132
popup = ~ device_id)
124
133
```
125
134
126
- ## Map geoshapes
135
+ ## Map geoshapes (polygons)
127
136
Again, we'll use ` sf::st_as_sf ` but select a WKT geoshape column.
128
137
129
138
``` {r, fig.width=9, fig.height=7}
130
139
geo_sf_poly <- geo_wkt %>% sf::st_as_sf(wkt="shape_location_shape_gps")
140
+ # Mapview using sf
131
141
mapview::mapview(geo_sf_poly, col.regions = sf::sf.colors(10))
142
+ # GGplot using sf
132
143
ggplot2::ggplot() +
133
144
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
134
147
leaflet::leaflet(data = geo_wkt) %>%
135
148
leaflet::addTiles() %>%
136
149
leaflet::addMarkers(
137
150
lng = ~ shape_location_shape_gps_longitude,
138
151
lat = ~ shape_location_shape_gps_latitude,
139
152
label = ~ device_id,
140
153
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