Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
cbgvalera committed May 16, 2024
1 parent 04300eb commit cfd88ba
Show file tree
Hide file tree
Showing 14 changed files with 6,120 additions and 269 deletions.
Binary file modified data/newshapefile/countries.dbf
Binary file not shown.
39 changes: 17 additions & 22 deletions lessons/ls05_shapefile_data.Rmd
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
---
title: '\ '
title: 'Read and Write Shapefiles'
output:
# word_document:
# toc: true
html_document:
number_sections: true
toc: true
toc_float: true
css: !expr here::here("global/style/style.css")
highlight: kate
pandoc_args: --shift-heading-level-by=-1
editor_options:
markdown:
wrap: 100
canonical: true
editor_options:
chunk_output_type: inline
markdown:
wrap: 72
---

```{r, include = FALSE, warning = FALSE, message = FALSE}
Expand All @@ -35,9 +32,7 @@ suppressMessages(source(here::here("lessons/ls05_shapefile_data_autograder.R")))
ggplot2::theme_set(new = theme_bw())
```

# Read and Write Shapefiles

## Introduction
# Introduction

We can built different types of **Thematic maps** using the `{ggplot2}` package.

Expand All @@ -49,7 +44,7 @@ But, how can we create *more* Thematic maps from **external Spatial data** gener

In this lesson we are going learn how to read and write **Shapefiles**, and also dive into the **`sf` objects** components!

## Learning objectives
# Learning objectives

1. Read Spatial data from **Shapefiles** using the `read_sf()` function from the `{sf}` package.

Expand All @@ -59,7 +54,7 @@ In this lesson we are going learn how to read and write **Shapefiles**, and also

4. Write Spatial data in **Shapefiles** using `write_sf()`.

## Prerequisites
# Prerequisites

This lesson requires the following packages:

Expand All @@ -76,11 +71,11 @@ pacman::p_load_gh("afrimapr/afrilearndata",
"wmgeolab/rgeoboundaries")
```

## Shapefiles
# Shapefiles

**Shapefiles** are the most common data format for *storing* Spatial data.

### How to read Shapefiles? {.unnumbered}
## How to read Shapefiles?

We can **read** Spatial data from **local files** with a `.shp` extension, as a ready-to-use **`sf` object**.

Expand Down Expand Up @@ -155,13 +150,13 @@ countries %>%

What do we see? The object consists of a 5-line **header** and a **data frame**.

### The `sf` header {.unlisted .unnumbered}
## The `sf` header

The *header* provides some contextualizing information about the rest of the object. You usually don't need to pay too much attention to this header, but we will go through it in some detail.

Let's go line-by-line through *the most relevant sections* of this header to see what these terms mean:

### Features and Fields {.unnumbered}
## Features and Fields

The first line of the header tells you the number of **features** and **fields** in the `sf` object:

Expand Down Expand Up @@ -196,7 +191,7 @@ q_nz_features_fields <- "C. 5 features and 4 fields"
```
:::

### Geometry {.unnumbered}
## Geometry

The second line of the header gives you the type of geometry in the `sf` object:

Expand Down Expand Up @@ -275,7 +270,7 @@ Some noteworthy points about this column:
- `geom_sf()` automatically recognizes the geometry column.
:::

### Geodetic CRS {.unnumbered}
## Geodetic CRS

The final header line tells us what Coordinate Reference System used.

Expand All @@ -293,7 +288,7 @@ The final header line tells us what Coordinate Reference System used.

For now, it is sufficient to know that coordinate systems are a *key component* of geographic objects. **We will cover them in detail later!**

## Delving into Shapefiles
# Delving into Shapefiles

A **single shapefile** is actually a *collection* of at least three files - `.shp`, `.shx`, and `.dbf`.

Expand Down Expand Up @@ -354,7 +349,7 @@ stores the *Attributes* for each shape?
```
:::

### How to write Shapefiles? {.unnumbered}
## How to write Shapefiles?

Let's write the `countries` object to an `countries.shp` file, located inside the `data/newshapefile/` folder, in two steps:

Expand Down Expand Up @@ -383,7 +378,7 @@ list.files(path = here("data/newshapefile"),
.score_print()
```

## Wrap up
# Wrap up

In this lesson, we have learned to **read** and **write** *Shapefiles* using the *`{sf}`* package, identify the **components** of an *`sf` object*, and their relation with the files within a *Shapefile*.

Expand Down
1,488 changes: 1,306 additions & 182 deletions lessons/ls05_shapefile_data.html

Large diffs are not rendered by default.

41 changes: 19 additions & 22 deletions lessons/ls05_shapefile_data_VIDEO_CODE_ALONG.Rmd
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
---
title: 'Read and Write Shapefiles'
output:
# word_document:
# toc: true
html_document:
number_sections: true
toc: true
toc_float: true
css: !expr here::here("global/style/style.css")
highlight: kate
pandoc_args: --shift-heading-level-by=-1
editor_options:
markdown:
wrap: 100
canonical: true
editor_options:
chunk_output_type: inline
markdown:
wrap: 72
---

```{r, include = FALSE, warning = FALSE, message = FALSE}
Expand All @@ -34,7 +31,7 @@ ggplot2::theme_set(new = theme_bw())

------------------------------------------------------------------------

## Introduction
# Introduction

• We built **Thematic maps** using `{ggplot2}`.

Expand All @@ -52,7 +49,7 @@ ggplot2::theme_set(new = theme_bw())

------------------------------------------------------------------------

## Learning objectives
# Learning objectives

1. Read Spatial data from **Shapefiles** using the `read_sf()` function from the `{sf}` package.

Expand All @@ -64,7 +61,7 @@ ggplot2::theme_set(new = theme_bw())

------------------------------------------------------------------------

## Prerequisites
# Prerequisites

This lesson requires the following packages:

Expand All @@ -83,11 +80,11 @@ pacman::p_load_gh("afrimapr/afrilearndata",

------------------------------------------------------------------------

## Shapefiles
# Shapefiles

• The most common data format for *storing* Spatial data.

### How to read Shapefiles? {.unnumbered}
## How to read Shapefiles?

• Using `read_sf()` from `{sf}`.

Expand Down Expand Up @@ -147,7 +144,7 @@ list.files(path = here("data/boundaries"),

------------------------------------------------------------------------

## Understanding `sf` objects
# Understanding `sf` objects

`"sf"` stands for [Simple Features](https://en.wikipedia.org/wiki/Simple_Features), a set of widely-used *standards for storing geospatial information in databases*.

Expand Down Expand Up @@ -175,13 +172,13 @@ countries %>%

• 5-line **header** and a **data frame**.

### The `sf` header {.unlisted .unnumbered}
## The `sf` header

• The *header* provides context about the rest of the object.

• Let's go through *the most relevant sections*:

### Features and Fields {.unnumbered}
## Features and Fields

• Tells you the number of **features** and **fields** in the `sf` object:

Expand Down Expand Up @@ -214,7 +211,7 @@ q_nz_features_fields <- "C. 5 features and 4 fields"
```
:::

### Geometry {.unnumbered}
## Geometry

• Gives you the *type of geometry* in the `sf` object:

Expand Down Expand Up @@ -295,7 +292,7 @@ First 10 features:
`geom_sf()` automatically recognizes the geometry column.
:::

### Geodetic CRS {.unnumbered}
## Geodetic CRS

• Tells us the Coordinate Reference System (CRS) used.

Expand All @@ -317,7 +314,7 @@ Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 83.64513

------------------------------------------------------------------------

## Delving into Shapefiles
# Delving into Shapefiles

• They are a *collection* of files,

Expand Down Expand Up @@ -376,7 +373,7 @@ stores the *Attributes* for each shape?
```
:::

### How to write Shapefiles? {.unnumbered}
## How to write Shapefiles?

• Let's write the `countries` object to an `countries.shp` file:

Expand All @@ -402,7 +399,7 @@ list.files(path = here("data/newshapefile"),

------------------------------------------------------------------------

## Wrap up
# Wrap up

• We **read** and **write** *Shapefiles* using the *`{sf}`* package,

Expand All @@ -420,15 +417,15 @@ list.files(path = here("data/newshapefile"),

------------------------------------------------------------------------

## Contributors {.unlisted .unnumbered}
# Contributors {.unlisted .unnumbered}

The following team members contributed to this lesson:

`r tgc_contributors_list(ids = c("avallecam", "lolovanco", "kendavidn"))`

------------------------------------------------------------------------

## References {.unlisted .unnumbered}
# References {.unlisted .unnumbered}

Some material in this lesson was adapted from the following sources:

Expand Down
2,401 changes: 2,401 additions & 0 deletions lessons/ls05_shapefile_data_VIDEO_CODE_ALONG.html

Large diffs are not rendered by default.

Loading

0 comments on commit cfd88ba

Please sign in to comment.