-
Notifications
You must be signed in to change notification settings - Fork 1
/
tutorial-1-create-spatial-object.Rmd
95 lines (65 loc) · 2.46 KB
/
tutorial-1-create-spatial-object.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
title: "Geo-spatial tutorial: create a simple feature"
author: "JR Ferrer-Paris"
institute: "Centre for Ecosystem Science<br/>UNSW Data Science Hub"
date: "March 2021 (updated: `r Sys.Date()`)"
output:
learnr::tutorial:
progressive: true
allow_skip: true
runtime: shiny_prerendered
description: >
Learn how to create spatial features with R package `sf` and visualise with `mapview`.
---
```{r setup, include=FALSE}
library(learnr)
library(sf)
require(leafpop)
library(leaflet)
library(mapview)
tutorial_options(
exercise.timelimit = 60,
# A simple checker function that just returns the message in the check chunk
exercise.checker = function(check_code, ...) {
list(
message = eval(parse(text = check_code)),
correct = logical(0),
type = "info",
location = "append"
)
}
)
knitr::opts_chunk$set(error = TRUE)
```
## Welcome
This is part 1 of a series of introductory tutorials to work with geo-spatial data in R. I prepared these tutorials as a intuitive "hands on" introduction, but I provide links for those interested in more background and theory.
In this tutorial, you will learn how to create a spatial object with package `sf` (simple features).
### Setup
I've preloaded the packages for this tutorial with
```{r eval = FALSE}
library(sf)
library(leaflet)
library(mapview)
library(leafpop)
```
For this tutorial we will **create our own spatial objects from scratch**, so we don't need to load any additional data.
```{r, eval=TRUE, child="01-create-sf-section.Rmd"}
```
### Good job!
We just created our first spatial object, how cool is that?
So we learned to:
- use package `sf`
- define a geometry with `st_points`
- assign a coordinate reference system with `st_crs`
- create a spatial object with `st_sf` by combining a data frame with a simple feature column with `st_sfc`
- combine `sf` objects with `rbind`
But what can we do with these sets of points? Let's do some more spatial stuff like calculating distance and mapping in the next section!
```{r, eval=TRUE, child="02-map-points-section.Rmd"}
```
### That's it for this tutorial!
Well, that was easy! wasn't it?
We learned to:
- calculate distance between points with `st_distance` and `st_nearest_feature`
- map two sets of points using `mapview`
I hope this has been useful and you feel more confident to start working with geo-spatial data in R.
Check the next tutorials in our [geospatial-data repository](https://github.com/UNSW-codeRs/geospatial-data-in-R)