-
Notifications
You must be signed in to change notification settings - Fork 4
/
Using_LIO_maps.Rmd
149 lines (114 loc) · 4.64 KB
/
Using_LIO_maps.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
title: "Using LIO background imagery for mapping in R"
author: "Erica Newton"
date: "`r format(Sys.Date(), '%b %d, %Y')`"
output:
html_document:
df_print: paged
pdf_document: default
---
```{r, setup, include=FALSE}
knitr::opts_chunk$set(message = FALSE)
knitr::opts_chunk$set(warning = FALSE)
```
# Use a georeferenced TIF as a background
- I created the .TIF by using the LIO topographic map as my baselayer in ArcGIS Pro, then exporting it as a georeferenced .TIF in ArcGIS Pro.
- Tip - use a custom large size in ArcGIS Pro and ensure output resolution is high; consider using Map Series for multiple backgrounds
```{r}
# install/load required libraries
#if (!require("pacman")) install.packages("pacman")
#pacman::p_load(raster, tidyverse, sf, RStoolbox)
library(tidyverse)
library(raster)
library(sf)
```
## Bring in georeferenced tif
```{r}
basemap <- brick("PeterboroughMap.tif")
# get the coordinate reference system
mycrs <- st_crs(basemap)
```
## Create some example spatial data to map on top
```{r}
# Choose a few random locations in Peterborough
my_points <- tibble(latitude = c(44.305907, 44.307612, 44.314083, 44.282756847),
longitude = c(-78.333753, -78.336279, -78.325517, -78.32322240),
name = c("point 1", "point 2", "point 3", "point 4"),
value = c("good", "best", "best", "satisfactory"))
# Convert to spatial points df
my_points <- st_as_sf(my_points,
coords = c("longitude", "latitude"),
crs = "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
# Make sure crs is the same as my base layer
my_points <- st_transform(my_points, mycrs)
area_of_interest <- st_buffer(st_as_sfc(st_bbox(dplyr::filter(my_points, value != "satisfactory"))), 250)
```
```{r}
# map in a ggplot2 framework
ggRGB(basemap, r = 1, g = 2, b = 3) +
geom_sf(data = my_points, aes(fill = value), size = 5, shape = 21) +
scale_fill_manual(values = c("mediumorchid3", "deeppink3", "dodgerblue4"),
breaks = c("best", "good", "satisfactory"), name = "Rating") +
geom_sf(data = area_of_interest, fill = NA, colour = "orange", size = 2) +
theme_void(base_size = 15) +
theme(legend.position = c(0.8, 0.8))
```
## Clip basemap to extent of points buffered by 200 m, then map again
```{r}
small_basemap <- crop(basemap, extent(st_buffer(my_points, 200)))
ggRGB(small_basemap, r = 1, g = 2, b = 3) +
geom_sf(data = my_points, aes(color = value), size = 5) +
theme_void(base_size = 15)
```
# For using rasters with leaflet:
- https://rstudio.github.io/leaflet/raster.html
# Extract backgrounds from an image service hosted on ArcGIS Online
- I'm currently waiting for help on getting this to work
- See https://github.com/R-ArcGIS/r-bridge/issues/54
- Note that you must have an installation of ArcGIS Pro + ArcGIS Online account for this + install r-ArcGIS bridge.
```{r arcbinding, eval=FALSE}
library(arcgisbinding)
arc.check_product()
## Read in a District Polygon from D.C.
r.bound <- arc.data2sf(arc.select(arc.open('https://maps2.dcgis.dc.gov/dcgis/rest/services/DCGIS_DATA/Planning_Landuse_and_Zoning_WebMercator/MapServer/31')))
## Choose the smallest zone
Blagdon <- r.bound %>% filter(NAME == "Blagden Alley Residential Transition Area")
## Set Boundary to Image Service
r.obj <- arc.open('https://imagery.dcgis.dc.gov/dcgis/rest/services/Ortho/Ortho_2019/ImageServer')
r.arc <- arc.raster(r.obj, extent = extent(Blagdon))
# NOT WORKING
#r.R <- as.raster(r.arc)
#plotRGB(r.R)
```
```{r}
mylake <- brick("lakeontario.tif")
gfsgn <- read.csv("gfsgn_sites.csv")
gfsgn <- gfsgn %>% filter(!is.na(LAT))
gn_points <- st_as_sf(gfsgn,
coords = c("LON", "LAT"),
crs = "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
# Make sure crs is the same as my base layer
gn_points <- st_transform(gn_points, mycrs)
ggRGB(mylake, r = 1, g = 2, b = 3) +
geom_sf(data = gn_points) +
theme_void(base_size = 15) +
theme(legend.position = c(0.8, 0.8))
```
```{r}
##crop to zoom in on lower bay and plot Fall 2018 sites
load(file="Allgear.Rdata")
CSMI_points <- st_as_sf(allgear,
coords = c("LONGITUDE", "LATITUDE"),
crs = "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
CSMI_points <- st_transform(CSMI_points, mycrs)
crop_mylake <- crop(mylake, extent(st_buffer(CSMI_points, 400)))
ggRGB(crop_mylake, r = 1, g = 2, b = 3) +
geom_sf(data = CSMI_points, size = 5) +
theme_void(base_size = 15)
```
```{r}
# Best places in Bruce County
BC <- brick("BruceCounty.tif")
ggRGB(BC, r = 1, g = 2, b = 3) +
theme_bw(base_size = 15)
```