-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathyojoa.Rmd
More file actions
121 lines (72 loc) · 2.07 KB
/
yojoa.Rmd
File metadata and controls
121 lines (72 loc) · 2.07 KB
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
---
title: "yojoa heat map"
author: "Matthew Ross"
date: "2/22/2019"
output: html_document
---
```{r}
library(tidyverse)
library(sf) # new goodness
library(mapview)
library(lubridate)
library(osmdata)
library(raster) #dead to me
library(sp) # also very dead to me.
library(gstat)
```
# Data read
```{r}
# Read in points
y <- read_csv('data/Yojoaheatmapfile.csv')
ys <- st_as_sf(y,coords=c('longitude','latitude'),crs=4326)
ys.m <- st_transform(ys,crs=26716) %>%
mutate(x=st_coordinates(.)[,1],
y=st_coordinates(.)[,2])
# Get state metadata
bb <- getbb('Santa Barbara, Honduras')
#Download Lago de Yojoa
lake <- opq(bbox=bb) %>%
add_osm_feature(key = 'natural', value = 'water') %>%
osmdata_sf() %>%
.$osm_polygons %>%
filter(name == 'Lago de Yojoa') %>%
st_transform(26716)
#Get bboxx info for yojoa
yo_box <- st_bbox(lake)
mapview(ys,zcol='Cu_mg_kg') +
mapview(lake) +
mapview(yo_box)
```
## Make a heatmap
```{r}
lake.sp <- as(lake,'Spatial')
lake.raster <- raster(lake.sp,res=100)
g <- as(lake.raster,'SpatialGrid')
y.sp <- as(ys.m,'Spatial')
metals = c('Cu_mg_kg','Zn_mg_kg','Cd_mg_kg','Pb_mg_kg')
for(i in 1:length(metals)){
formula = as.formula(paste(metals[i], 1,sep='~'))
cu_s <- gstat(id=metals[i],formula=formula,data=y.sp)
z <- interpolate(lake.raster,cu_s) %>% round(.,1)
z <- mask(z,lake.sp)
cu <- mapview(z,na.col=NA,col.regions=mapviewGetOption('vector.palette')) +
mapview(ys.m,zcol=metals[i])
mapshot(cu,url=paste0('out/',metals[i],'.html'))
}
```
# The New Way
```{r}
library(stars)
lake_stars <- st_bbox(lake) %>%
st_as_stars(dx = 100) %>%
st_crop(lake)
interp = idw(Zn_mg_kg~1, y.sp, lake_stars)
mapview(interp,na.col=NA,col.regions=mapviewGetOption('vector.palette')) +
mapview(y.sp, zcol = 'Zn_mg_kg')
```
## Variogram
```{r}
v_zn <- variogram(Zn_mg_kg ~ 1, y.sp)
#v.m = fit.variogram(v, vgm(1, "Exp", 50000, 1))
v.m = fit.variogram(v_zn, vgm(1, 'Mat', 50,1))
```