-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshapes.Rmd
163 lines (112 loc) · 3.51 KB
/
shapes.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
---
title: "Shapes"
author: "Michael Sumner"
date: "20/09/2017"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.width=7, fig.height = 7)
```
# Shapes
This is not a shapefile.
It's a `SpatialPolygonsDataFrame`, rendered in a particular way using the R programming language.
```{r}
library(aceecostats)
library(sp)
plot(aes_region_simple, col = aes_region_simple$colour)
```
```{r}
library(mapview)
mapview(aes_region_ll, col.regions = aes_region_ll$colour) # viridis::viridis(nrow(aes_region_ll)))
```
It can be rendered in various ways.
```{r}
library(anglr)
mesh <- anglr(aes_region_simple)
plot(mesh)
rgl::rglwidget()
```
```{r}
library(anglr)
rgl::rgl.clear()
mesh <- anglr(aes_region_simple)
plot(globe(mesh))
rgl::rglwidget()
```
Finally, we can nowadays actually edit or create our own drawings interactively, but this is still
an early stage.
```{r}
library(mapedit)
```
There's no easy way into this, it's a DEEP DIVE.
```{r}
library(sfdct)
aes_triangles <- ct_triangulate(st_as_sf(aes_region_simple))
plot(aes_triangles$geometry, col = NA)
```
# Simple shape
A map of Antarctica is pretty complicated, so let's take it back a little.
```{r}
library(silicate)
data("minimal_mesh")
library(sf)
print(minimal_mesh)
plot(minimal_mesh)
```
This simple situation hides a lot of problems.
## First problem
It's pretty complicated.
```{r}
str(unclass(minimal_mesh$geom))
```
## Second problem
There are three shapes here, but only two values. (One of the shapes is a hole).
```{r}
minimal_mesh$a
```
## Third problem
There are shared-elements between these two objects, two coordinates and one edge. But how can we know this?
```{r}
op <- par(xpd = NA)
plot(minimal_mesh, col = NA)
ring1 <- minimal_mesh$geom[[1]][[1]][[1]]
points(ring1)
text(ring1, label = sprintf("%s,%s", ring1[, 1], ring1[, 2]), pos = 2, adj = 3, col = "dodgerblue")
ring2 <- minimal_mesh$geom[[2]][[1]][[1]]
points(ring2)
text(ring2, label = sprintf("%s,%s", ring2[, 1], ring2[, 2]), pos = 4, adj = 3, col = "firebrick")
ring3 <- minimal_mesh$geom[[1]][[1]][[2]]
points(ring3)
text(ring3, label = sprintf("%s,%s", ring3[, 1], ring3[, 2]), pos = 1, adj = 3, col = "black")
par(op)
```
## Standard algorithms don't know about the shapes
```{r}
## two POLYGONs, composed of three rings p1+p2 and p3
p1 <- cbind(x = c(0, 0, 0.75, 1, 0.5, 0.8, 0.69, 0),
y = c(0, 1, 1, 0.8, 0.7, 0.6, 0, 0))
p2 <- cbind(x = c(0.2, 0.2, 0.3, 0.5, 0.5, 0.2),
y = c(0.2, 0.4, 0.6, 0.4, 0.2, 0.2))
p3 <- cbind(x = c(0.69, 0.8, 1.1, 1.23, 0.69),
y = c(0, 0.6, 0.63, 0.3, 0))
library(sf)
g <- data.frame(two_polygons = 1:2)
g[["geometry"]] <- st_sfc(st_polygon(list(p1, p2[nrow(p2):1, ])), st_polygon(list(p3)))
g <- st_as_sf(g)
## Delaunay triangulation of the polygon vertices, grouped by feature
gt <- g
st_geometry(gt) <- st_triangulate(st_geometry(g))
op <- par(mfrow = c(1, 2))
plot(g)
plot(gt, col = scales::alpha(c("blue", "yellow"), 0.3), main = "convex triangulation")
plot(st_geometry(g), add = TRUE, lwd = 4)
```
# This is simple features
- shapes are represented as paths so only planar polygonal shapes are possible
- the standard allows for XY[Z[M]] geometry,but this is not extensible - no capacity to store data against component geometry elements
- no internal topology (no vertex-, edge-, or path-sharing).
## Return to the blocky triangles in original
- resize the triangles for a smoother curve
- elevate with bathymetry
- show the North Carolina example
# Software