-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSurvey_to_points.Rmd
77 lines (56 loc) · 2.57 KB
/
Survey_to_points.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
---
title: "Tree Survey to Point Layer"
author: "Thomas Estabrook"
date: "7/7/2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(sf)
library(dplyr)
library(cartography)
library(ggplot2)
```
```{r}
# read in survey tree csv file
survey_trees <- read.csv("C:/Users/User/OneDrive - Umich/School/Capstone Project/Data/August_18_Tree_Survey/survey_0.csv")
# read in shapefile for plot locations
sample_plots <- read_sf("C:/Users/User/OneDrive - Umich/School/Capstone Project/Data/Sample_Plots_shapefile/SamplePlots.shp")
#source CRS: EPSG 2253, units are feet
```
```{r}
# get the x and y coordinate values from the sample plot shapefile. Remove unneeded columns to save memory and prevent confusion
sample_plots <- sample_plots %>%
mutate(X_plot = st_coordinates(sample_plots[,7])[,"X"]) %>%
mutate(Y_plot = st_coordinates(sample_plots[,7])[,"Y"]) %>%
select(!c(Coordinate, GlobalID, CreationDa, Creator, EditDate, Editor, H_precisio, X, Y))
# Eliminate the old geometry information
sample_plots <- st_drop_geometry(sample_plots)
```
```{r}
# Here we do the transfomation to correct for magnetic declination
theta = 0.123 # 5 degrees converted to radians, negative for clockwise correction(?)
# First we join the survey points to the sample locations (with coordinates labeled as X and Y). Then we eliminate some columns, and apply the rotation to the local x and y values of the sample points. Finally we get the final x and y values by adding the transformed local x and y to the sample site origin point x and y values.
survey_trees <- survey_trees %>%
inner_join(sample_plots, by = c("Plot.ID" = "CID")) %>%
select(!c(x,y,Cartesian.or.Polar.Coordinates.,GlobalID, CreationDate, Creator, EditDate, Editor,Surveyor,Notes.x,Notes.y)) %>%
mutate(new_x = (X.value*cos(theta)) - (Y.value*sin(theta))) %>%
mutate(new_y = (Y.value*cos(theta)) + (X.value*sin(theta))) %>%
mutate(final_x = X_plot + new_x) %>%
mutate(final_y = Y_plot + new_y)
```
```{r}
# Now we use the st_as_sf function to turn the dataframe into a shapefile, where the x and y in the spatial reference system come from the x and y columns in the data
proj_crs <- st_crs(sample_plots)
tree_points <- st_as_sf(survey_trees, coords = c("final_x", "final_y"), crs=proj_crs)
```
```{r}
# Optionally plot the data. Doesn't show up very well due to small size
ggplot() +
geom_sf(data = tree_points) +
ggtitle("Map of Plot Locations")
```
```{r}
# Output the final shapefile
write_sf(tree_points, "C:/Users/User/OneDrive - Umich/School/Capstone Project/Data/tree_points_Aug_18.shp")
```