Skip to content

Commit

Permalink
Pertaining to issues #63 and #61
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha-sharma123 committed Dec 19, 2021
1 parent 2297b7e commit 65626c6
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 131 deletions.
42 changes: 26 additions & 16 deletions 02-mapping-data.Rmd

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions 05-relational-databases.Rmd
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
```{r, include=FALSE}
baseurl <- "https://ubc-geomatics-textbook.github.io/geomatics-textbook/"
covlicence <- "https://opendata.vancouver.ca/pages/licence/"
library("dplyr")
library("rgdal")
library("leaflet")
library("xtable")
library("plyr")
library("dplyr")
```


## Relational Databases {#relational-databases}

You have almost certainly used a relational database in some form during your life, probably without even realizing it. Relational databases are foundational for information management in a GIS. In this chapter, we will look at the formal construction of relational databases, how they are used across a wide range of fields, and how we can use them to analyze spatial and aspatial information for environmental management.
Expand Down Expand Up @@ -38,7 +40,7 @@ Suppose you have collected some data about some trees. You might have organized
Within a RDBMS, we find **relational databases**, which are highly structured tables comprised of rows and columns. In fact, a table in a relational database is called a **relation**, a row is a **tuple**, and a column is an **attribute**. Relational databases are a great way to store simple data structures that can be organized into a relation with tuples and attributes. When we say that a table or relation is "structured", we are referring to the fact that the data are organized according to a database **schema**, which is a set of constraints that ensure data integrity and consistency. For example, our set of trees likely all contain the same types of information and this can be easily organized into a relation. Suppose we measured the height, diameter at breast height (DBH), and species of each tree, then our relation would look like Figure \@ref(fig:5-tabular-data-spatial-data).

```{r 5-tabular-data-spatial-data, fig.cap = fig_cap, out.width= "75%", echo = FALSE}
fig_cap <- paste("Tabular and spatial data are related by a Relational Database Management System (RDBMS) in a Geographic Information System (GIS). Animated figure can be viewed in the web browser version of the textbook. Images of Douglas-Fir and Western Hemlock trees by Natural Resources Canada, Canadian Forest Service, modified with permission.")
fig_cap <- paste0("Tabular and spatial data are related by a Relational Database Management System (RDBMS) in a Geographic Information System (GIS).<a href='",baseurl,"#fig:5-tabular-data-spatial-data'>Animated figure can be viewed in the web browser version of the textbook</a>. Animated figure can be viewed in the web browser version of the textbook. Images of Douglas-Fir and Western Hemlock trees by Natural Resources Canada, Canadian Forest Service, modified with permission.")
knitr::include_graphics(here::here("images", "05-tabular-data-spatial-data.png"))
```
<br/>
Expand All @@ -50,7 +52,7 @@ The schema for the very simple example above would include the constraint and ex
More formally, a relation $R$ is a _subset_ of two sets, $A$ (tuples) and $B$ (attributes). The product of these sets $A×B$ is called the **Cartesian product**. In the same way that Cartesian coordinates are ordered pairs of values from two axes, the Cartesian product of two sets gives us an ordered pair of elements $(a,b)$ from sets $A$ and $B$, where $a$ is an element in the set $A$, written as $a∈A$, and $b$ is an element of set $B$, written as $b∈B$. Therefore, $R$ is both the Cartesian product as well as any subset of $A×B$.

```{r 5-cartesian-product, fig.cap = fig_cap, out.width= "75%", echo = FALSE}
fig_cap <- paste("Cartesian product A×B of A (tuples) and B (attributes). Image by [Quartl](https://en.wikipedia.org/wiki/Cartesian_product#/media/File:Cartesian_Product_qtl1.svg), CC BY-SA 3.0.")
fig_cap <- paste0("Cartesian product A×B of A (tuples) and B (attributes). Image by [Quartl](https://en.wikipedia.org/wiki/Cartesian_product#/media/File:Cartesian_Product_qtl1.svg), CC BY-SA 3.0.")
knitr::include_graphics(here::here("images", "05-cartesian-product.png"))
```
<br/>
Expand Down Expand Up @@ -415,7 +417,7 @@ knitr::kable(
Figure \@ref(fig:5-boolean-and) illustrates what is going on here, we are only returning the tuples that evaluate $true$ for both statements. Hence, Boolean $AND$ is equivalent to multiplying two Boolean truth values together. You should also recognize that a Boolean $AND$ is equivalent to what a set intersection $A∩B$ achieves between two relations.

```{r 5-boolean-and, fig.cap = fig_cap, out.width= "75%", echo = FALSE}
fig_cap <- paste("Boolean A AND B returns the area shaded blue. Animated figure can be viewed in the web browser version of the textbook. Pickell, CC-BY-SA-4.0.")
fig_cap <- paste0("Boolean A AND B returns the area shaded blue. <a href='",baseurl,"#fig:5-boolean-and'>Animated figure can be viewed in the web browser version of the textbook</a>. Pickell, CC-BY-SA-4.0.")
knitr::include_graphics(here::here("images", "05-boolean-and.png"))
```
<br/>
Expand All @@ -432,7 +434,7 @@ knitr::kable(
Figure \@ref(fig:5-boolean-or) illustrates the case of the Boolean $OR$. As you can see, it returns everything where either of the statements evaluate to $true$, regardless if the other statement is $false$. You should also recognize that a Boolean $OR$ is equivalent to what a set union $A∪B$ achieves between two relations.

```{r 5-boolean-or, fig.cap = fig_cap, out.width= "75%", echo = FALSE}
fig_cap <- paste("Boolean A OR B returns the area shaded blue. Animated figure can be viewed in the web browser version of the textbook. Pickell, CC-BY-SA-4.0.")
fig_cap <- paste0("Boolean A OR B returns the area shaded blue. <a href='",baseurl,"#fig:5-boolean-or'>Animated figure can be viewed in the web browser version of the textbook</a>. Pickell, CC-BY-SA-4.0.")
knitr::include_graphics(here::here("images", "05-boolean-or.png"))
```
<br/>
Expand All @@ -449,7 +451,7 @@ knitr::kable(
Figure \@ref(fig:5-boolean-not) illustrates how Boolean $NOT$ essentially negates or inverts the statement that follows. In this case, instead of returning the Western Hemlock tuples, $NOT(species=WesternHemlock)$ returns "everything except" Western Hemlock, which is also equivalent to $species≠WesternHemlock$.

```{r 5-boolean-not, fig.cap = fig_cap, out.width= "75%", echo = FALSE}
fig_cap <- paste("Boolean A NOT B returns the area shaded blue. Animated figure can be viewed in the web browser version of the textbook. Pickell, CC-BY-SA-4.0.")
fig_cap <- paste0("Boolean A NOT B returns the area shaded blue. <a href='",baseurl,"#fig:5-boolean-not'>Animated figure can be viewed in the web browser version of the textbook</a>. Pickell, CC-BY-SA-4.0.")
knitr::include_graphics(here::here("images", "05-boolean-not.png"))
```
<br/>
Expand All @@ -466,7 +468,7 @@ knitr::kable(
Figure \@ref(fig:5-boolean-xor) illustrates how Boolean $XOR$ excludes all the tuples that evaluate to $true$ for both statements. In the example above, tuples ID=2 and ID=3 are excluded because both of the statements for height and species are $true$.

```{r 5-boolean-xor, fig.cap = fig_cap, out.width= "75%", echo = FALSE}
fig_cap <- paste("Boolean A XOR B returns the area shaded blue. Animated figure can be viewed in the web browser version of the textbook. Pickell, CC-BY-SA-4.0.")
fig_cap <- paste0("Boolean A XOR B returns the area shaded blue. <a href='",baseurl,"#fig:5-boolean-xor'>Animated figure can be viewed in the web browser version of the textbook</a>. Pickell, CC-BY-SA-4.0.")
knitr::include_graphics(here::here("images", "05-boolean-xor.png"))
```
<br/>
Expand Down Expand Up @@ -561,7 +563,7 @@ knitr::kable(
Depending on the schema of the two relations being joined, the number of tuples joined from one relation to another can vary and is known as **cardinality**. In the simplest case, one tuple in $R$ is joined to one tuple in $S$, and this cardinality is known as **one-to-one** usually expressed as 1:1. The natural join example above, $R⋈S$, is an example of **one-to-many** (1:M) or **many-to-one** (M:1) cardinality because one species tuple found in $S$ corresponds to many species tuples in $R$. Finally, **many-to-many** (M:M) cardinality describes the case where there are multiple tuples in $R$ that correspond to multiple tuples in $S$. An example of a many-to-many relationship might be many species of trees in $R$ that correspond to many forest stands in $S$. In other words, a forest stand might be comprised of many species and any particular species might be found in many forest stands. Figure \@ref(fig:5-join-cardinality) illustrates how cardinality might emerge depending on the relational schema and problem at hand.

```{r 5-join-cardinality, fig.cap = fig_cap, out.width= "75%", echo = FALSE}
fig_cap <- paste("Cardinality of joins between relations R and S. Animated figure can be viewed in the web browser version of the textbook. Pickell, CC-BY-SA-4.0.")
fig_cap <- paste("Cardinality of joins between relations R and S. <a href='",baseurl,"#fig:5-join-cardinality'>Animated figure can be viewed in the web browser version of the textbook</a>. Pickell, CC-BY-SA-4.0.")
knitr::include_graphics(here::here("images", "05-join-cardinality.png"))
```
<br/>
Expand Down Expand Up @@ -767,8 +769,7 @@ m1 <- leaflet(full.results_proj) %>%
Figure \@ref(fig:5-vegetation-diversity-leaflet) shows a map of the vegetation diversity score at the DA level in Vancouver. The vegetation diversity score and the normalized aggregated vulnerability score are linked to each DA and can be viewed as you hover o-ver the DA.

```{r 5-vegetation-diversity-leaflet, fig.cap = fig_cap, out.width= "75%", echo = FALSE}
fig_cap <- paste("An example of choropleth map displaying vegetation diversity for each dissemination area in Vancouver. Data from City of Vancouver and licensed under the Open Government License - Vancouver. Animated figure can be viewed in the web browser version of the textbook. Lam, CC-BY-SA-4.0.")
m1
fig_cap <- paste0("An example of choropleth map displaying vegetation diversity for each dissemination area in Vancouver.<a href='",baseurl,"#fig:5-vegetation-diversity-leaflet'>Animated figure can be viewed in the web browser version of the textbook</a>.Data from City of Vancouver and licensed under the <a href='",covlicence,">Open Government License - Vancouver</a>. Lam, CC-BY-SA-4.0.")
```
<br/>

Expand Down
8 changes: 4 additions & 4 deletions 07-topology-and-geocoding.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Vertex, Node, Pseudonode, Dangle, Planar Topology, Non-Planar Topology, Geocodin

[Chart showing combinations of point, line, and polygon geometries.]
```{r 7-geometry-combinations, echo=FALSE, out.width = '75%', fig.cap=fig_cap}
fig_cap <- paste("Caption here. Animated figure can be viewed in the web browser version of the textbook. Author, CC-BY-SA-4.0.")
fig_cap <- paste0("Caption here. Author, CC-BY-SA-4.0.")
knitr::include_graphics("images/07-geometry-combinations.png")
```

Expand Down Expand Up @@ -68,23 +68,23 @@ As we have seen from Chapter 3, lines are often used to represent phenomena that

[plot showing line segment A]
```{r 7-, echo=FALSE, out.width = '75%', fig.cap=fig_cap}
fig_cap <- paste("Caption here. Animated figure can be viewed in the web browser version of the textbook. Author, CC-BY-SA-4.0.")
fig_cap <- paste0("Caption here. Author, CC-BY-SA-4.0.")
knitr::include_graphics("images/07-.png")
```

A network of streams and rivers is based on the hydrological knowledge system that explains how water moves over a terrain surface. In both theory and practice, we know that water flows from higher elevations to lower elevations with limited expections. Thus, we expect that streams will connect with other streams and continue to flow towards some outlet such as an ocean. **Connection** refers to the fact that the endpoint node of one stream will fall somewhere on another stream segment. Where two line segments come together, it is possible for one segment $A$ to "undershoot" the other segment $B$, resulting in the end node of segment $A$ appropriately named a **dangle** and a loss of connection. As well, **pseudonodes** can occur when a node does not actually terminate a line segment at a junction, for example, between two streams or roads.

[image showing pseudonode, connection, dangle]
```{r 7-, echo=FALSE, out.width = '75%', fig.cap=fig_cap}
fig_cap <- paste("Caption here. Animated figure can be viewed in the web browser version of the textbook. Author, CC-BY-SA-4.0.")
fig_cap <- paste0("Caption here.Author, CC-BY-SA-4.0.")
knitr::include_graphics("images/07-.png")
```

Dangles are the opposite case to **intersections**, which occur when two line segments cross each other. With planar topology, intersections must be modeled with a shared node representing the intersection location. For example, suppose line segment $B$ has a set of vertices, $[[0,1],[2,1],[4,1]]$. If line segments $A$ (defined above) and $B$ are mapped together, then they will intersect at $[1,1]$, which is not a vertex represented in either segment. Thus, the intersection of $A$ and $B$ with planar topology would yield four new segments: $C=[[1,0],[1,1]]$, $D=[[0,1],[1,1]]$, $E=[[1,1],[1,3],[1,5]]$, and $E=[[1,1],[2,1],[4,1]]$. Figure \@ref(fig:7-intersection) illustrates how all four of these new segments share the same node $[1,1]$ at the intersection of $A$ and $B$.

[plot showing A and B crossing and the resulting intersection described above]
```{r 7-, echo=FALSE, out.width = '75%', fig.cap=fig_cap}
fig_cap <- paste("Caption here. Animated figure can be viewed in the web browser version of the textbook. Author, CC-BY-SA-4.0.")
fig_cap <- paste0("Caption here. Author, CC-BY-SA-4.0.")
knitr::include_graphics("images/07-.png")
```

Expand Down
Loading

0 comments on commit 65626c6

Please sign in to comment.