Introduction

In this Notebook you’ll practice importing some tabular data in to R, converting it to a simple feature data frame, projecting it, and saving it to disk as a GeoJSON file.


1) Import the missing persons CSV file:

miss_pips_df <- read.csv("./data/yosemite_missing_people.csv", stringsAsFactors = FALSE)

head(miss_pips_df)
# View(miss_pips_df)


Let’s reduce the number of columns:

library(dplyr)

miss_pips_thin_df <- miss_pips_df |> 
  select(Long, Lat, Type, CaseNumber, IncidYear, ContactMet, IncidType, NumberofSu, GroupDynam, 
         SubjectCat, SubSex, SubAge, IncidContr, Scenario, RescueMeth, Incident_N, Found_GR_N)

head(miss_pips_thin_df)


2) Convert the data frame to a simple feature data frame

For convenience, here are some EPSG numbers:

epsg_geo_wgs84 <- 4326       ## General long-lat
epsg_utm11n_nad83 <- 26911   ## use this one for YNP

Convert a data frame to a spatial object with st_as_sf(). You have to specify the names of the columns that contain the coordinates, and the EPSG number of the coordinates.

library(sf)

miss_pips_sf <- st_as_sf(miss_pips_thin_df, 
                         coords = c("Long", "Lat"), 
                         crs = epsg_geo_wgs84) 

miss_pips_sf
Simple feature collection with 213 features and 15 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: -119.8801 ymin: 37.50101 xmax: -119.2493 ymax: 38.03343
Geodetic CRS:  WGS 84
First 10 features:
   Type CaseNumber IncidYear         ContactMet       IncidType NumberofSu            GroupDynam
1   IPP   20090248      2009 Subject Cell Phone          Search          1          Solo Subject
2   IPP   20090652      2009   Reported Missing Separated Party          1          Solo Subject
3   IPP   20090940      2009   Reported Missing         Overdue          1          Solo Subject
4   IPP   20091134      2009 Subject Cell Phone          Search          1          Solo Subject
5   IPP   20091252      2009   Reported Missing Separated Party          1          Solo Subject
6   IPP   20091345      2009   Reported Missing         Overdue          1          Solo Subject
7   IPP   20091382      2009   Reported Missing         Overdue          2 Group Stayed Together
8   IPP   20091583      2009   Reported Missing         Overdue          2 Group Stayed Together
9   IPP   20091755      2009 Subject Cell Phone          Search          3 Group Stayed Together
10  IPP   20091760      2009   Reported Missing          Search          1          Solo Subject
           SubjectCat             SubSex SubAge           IncidContr   Scenario   RescueMeth
1  Mental Retardation               Male     31             Darkness       Lost Snow Machine
2               Hiker               Male      0              Unknown  Separated      Walkout
3       Child (13-15)               Male     14              Unknown    Overdue        Other
4               Hiker               Male     35             Snow/Ice       Lost   Helicopter
5         Child (4-6)               Male      6              Unknown  Separated        Other
6               Hiker               Male     29              Unknown    Overdue        Other
7             Climber Group  - Mixed Sex      0       Weather - Cold    Overdue      Walkout
8               Hiker  Group - All Males      0             Darkness       Lost      Vehicle
9               Hiker  Group - All Males      0 Weather - Visibility       Lost   Helicopter
10    Substance Abuse               Male     23                Drugs Despondent        Other
                                                                                                                                                                 Incident_N
1                                                               Subject was snowshoeing, became disoriented, and called for help. Subject described as mentally challenged.
2                                                                                 Subject described as teenage male; found in under half an hour from reported missing time
3                                                                                 Subject hiked Yosemite Falls Trail and was found at his bike after being reported overdue
4                                Subject hiked up Yosemite falls Trail and to North Dome; planned to hike back to the Valley via Snow Creek Trail but lost tral due to snow
5                                                                                Subject became separated from father and returned to his hotel room to wait for his return
6                                                          Subject took shortcut off trail while hiking Upper Yosemite Falls Trail and became separated from hiking partner
7                                                                                                                     Two subjects, one M and one F, overdue after climbing
8                                           Two M subjects lost the trail in the darkness after hiking to Taft Point; attempted to find a high point to reorient themselves
9                                                                          Three M subjects intentionally left the trail to take a shortcut to some bathrooms that they saw
10 Subject ingested LSD and was last seen running nude through Upper Pines Campground; subject found deceased with fatal injuries consistent with a fall from great heights
                                                                                                        Found_GR_N
1  Found just south of the top of the Eale Chair Lift at Badger Pass Ski at an elevation of approximately 8,200 ft
2                                                                  Found in the parking lot looking for his mother
3                                                                             Found at LKP after hike was complete
4                                          Found in the area of Indian Ridge, approximately 300 feet off the trail
5                                                                                Found at Yosemite Lodge room 4623
6                                                                            Found near the Bank3-Way intersection
7                               Found near the base of Drug Dome and in the forested area leading to the trailhead
8                        Found walking along the road approximately 2 miles west of the Sentinel Dome parking area
9                        Found on the west-facing slope of Grizzly Peak at approximately -119 33.235 and 37 43.906
10         Found along the cliff bands below the Porcelain Wall on the west shoulder of Half Dome near Mirror Lake
                     geometry
1  POINT (-119.6632 37.66355)
2   POINT (-119.8099 37.7691)
3  POINT (-119.5958 37.74595)
4  POINT (-119.5599 37.75631)
5  POINT (-119.5937 37.74561)
6  POINT (-119.6064 37.74521)
7  POINT (-119.4291 37.86868)
8  POINT (-119.5864 37.71233)
9  POINT (-119.5271 37.74873)
10 POINT (-119.5634 37.73601)


3) Project the missing persons layer to UTM 11N (NAD83)

Hint. Answer

## Your answer here


4) Save as GeoJSON

You can save a spatial object to disk with st_write(). R will figure out what format to use based on the file name extension.

Save the Missing Persons layer as GeoJSON: Answer

## Your answer here
LS0tDQp0aXRsZTogIk1hbmlwdWxhdGUgYSBTaW1wbGUgRmVhdHVyZSBEYXRhIEZyYW1lIg0Kb3V0cHV0OiANCiAgaHRtbF9ub3RlYm9vazoNCiAgICB0b2M6IHllcw0KICAgIHRvY19mbG9hdDogeWVzDQotLS0NCg0KIyMgSW50cm9kdWN0aW9uDQoNCkluIHRoaXMgTm90ZWJvb2sgeW91J2xsIHByYWN0aWNlIGltcG9ydGluZyBzb21lIHRhYnVsYXIgZGF0YSBpbiB0byBSLCBjb252ZXJ0aW5nIGl0IHRvIGEgc2ltcGxlIGZlYXR1cmUgZGF0YSBmcmFtZSwgcHJvamVjdGluZyBpdCwgYW5kIHNhdmluZyBpdCB0byBkaXNrIGFzIGEgR2VvSlNPTiBmaWxlLg0KDQpcDQoNCiMjIDEpIEltcG9ydCB0aGUgbWlzc2luZyBwZXJzb25zIENTViBmaWxlOg0KDQpgYGB7ciBjaHVuazAxfQ0KbWlzc19waXBzX2RmIDwtIHJlYWQuY3N2KCIuL2RhdGEveW9zZW1pdGVfbWlzc2luZ19wZW9wbGUuY3N2Iiwgc3RyaW5nc0FzRmFjdG9ycyA9IEZBTFNFKQ0KDQpoZWFkKG1pc3NfcGlwc19kZikNCiMgVmlldyhtaXNzX3Bp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