Skip to main content

Chapter exercise: ArcGIS Data with arcpullr

Medical Facilities from NC OneMap

This exercise goes with Chapter 14, ArcGIS Data with arcpullr. It builds on the Census Data exercise from Chapter 13, which also downloaded data through an API. It should take you about one hour. Read this whole section before you start.

TipGet the exercise file

Download arcpullr-exercise.Rmd

Save it in a new folder called arcpullr-exercise inside your geog215 folder, open it in RStudio, and work through it from top to bottom. Everything on this page is also at the top of the file.

Purpose

Skills you’ll practice. By the end of this exercise you will be able to:

  1. Read a layer’s REST Services Directory page and record its geometry type, coordinate system, record limit, and field names.
  2. Download a layer from an ArcGIS feature service into R as an sf object with get_spatial_layer().
  3. Write where clauses in SQL, with =, IN, AND, and text values in single quotes.
  4. Explain why filtering on the server is better than downloading everything and filtering in R.
  5. Check, project, map, and save a downloaded layer, and record when you downloaded it.

Knowledge you’ll gain. You’ll find out how many licensed medical facilities North Carolina has, what kinds they are, and how Orange and Durham counties compare.

Why this matters. State and local governments publish most of their GIS data (parcels, schools, roads, parks, hospitals) on ArcGIS portals such as NC OneMap. Being able to pull exactly the features you need straight into R, with a script that records where they came from, makes your work faster and reproducible. Portal layers change over time, so knowing how to document a download is part of doing honest analysis.

Task

Work through Parts 1 to 7 in order, top to bottom. In each part:

  • Read the short explanation, then do each step marked with a bullet (•).
  • Wherever you see ___, replace it with the missing code before you run the chunk. Where you see # your code here, write the code yourself.
  • Answer each question (Q1, Q2, …) in a sentence or two of Markdown, where it says Your answer here.
  • This exercise downloads data, so you need an internet connection. The full statewide download in Part 5 takes a little while.
  • Your numbers may differ slightly from a classmate’s if NC OneMap updates the layer between your downloads. That’s expected; say when you downloaded it.
Part What you’ll do About
1 Set up your file and load the packages 4 min
2 Read the layer’s REST page 10 min
3 Download one county 8 min
4 Write where clauses 12 min
5 Filter on the server or in R? 8 min
6 Project, map, and save 13 min
7 Reflect, knit, and turn in 5 min

Turn in your .Rmd file and your knitted .html file on Canvas.

Criteria for success

Use this checklist before you turn your work in. Each item matches a row of the rubric below.

Criterion Full credit Partial credit No credit
Knits (2 pts) Knits to HTML with no errors Knits, but some chunks have errors shown Doesn’t knit, or no HTML turned in
REST page (2 pts) Q1 and Q2 record the details correctly Some details missing Not done
Downloads and where clauses (5 pts) Every request correct, with correct SQL Most correct Many missing or wrong
Questions (7 pts) Q3 to Q10 answered with numbers and reasons Some answers missing or without reasons Most answers missing
Map (3 pts) Projected, with title, legend title, and credits with the download date Some parts missing Not done
Reflection (1 pt) All three answered Missing

What a good answer looks like. Here is a question, a weak answer, and a strong one.

Question: Why use a where clause instead of filter()?

Weak answer: “It’s faster.”

Strong answer: “With where, the server sends only the 61 Orange County facilities instead of all 6,800 in the state, so the download took a fraction of the time. For a big layer like statewide parcels, downloading everything might not even be possible, and the where clause also records in my script exactly which features I used.”

The strong answer uses numbers from the output, explains why, and says when it matters most.

IMPORTANT! Save often. Before you knit, choose Run > Restart R and Run All Chunks to make sure every chunk works from a fresh start.