-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathslides.Rmd
80 lines (54 loc) · 1.85 KB
/
slides.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
---
title: "R for spatial vector data"
author: "Loïc Dutrieux, Jan Verbesselt, Sytze de Bruyn, Benjamin Brede"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: slidy_presentation
---
## Sp classes
| Geometry | class | attribute |
|------------- |----------------- |------------- |
| points | *SpatialPoints* | No |
| points | *SpatialPointsDataFrame* | data.frame |
| line | *Line* | No |
| lines | *Lines* | No |
| lines | *SpatailLines* | No |
| lines | *SpatialLinesDataFrame* | data.frame |
| rings | *Polygon* | No |
| rings | *Polygons* | No |
| rings | *SpatailPolygons* | No |
| rings | *SpatialPolygonsDataFrame* | data.frame |
---
## Structure of a Spatial*DataFrame object
```{r}
library(sp)
data(meuse)
coordinates(meuse) = c("x", "y")
str(meuse)
```
---
## Structure of a Spatial*DataFrame object (2)
* A SpatialPoints object
* Coordinates
* A coordinate reference system
* A spatial extent
* A dataframe
### Implications
*Manipulating sp objects is very similar to data.frames manipulation*
### Subsetting
```{r}
meuseClean <- meuse[!is.na(meuse$landuse),]
meuseSub <- meuseClean[meuseClean$landuse == 'Ah',]
```
---
```{r}
plot(meuse, pch = 20, col = 'red')
plot(meuseSub, pch = 20, col = 'green', add = TRUE)
```
---
## Manipulating geometries
**rgeos** package
* `gBuffer()`: Create buffer around geometries
* `gDistance()`: Distance between a set of *projected* points
* `gDifference()`: Difference between 2 geometries
* `gArea()`: Calculate area of given geometry
* `gIntersection()`: Intersection between two geometries