-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGWR.Rmd
More file actions
138 lines (97 loc) · 2.65 KB
/
GWR.Rmd
File metadata and controls
138 lines (97 loc) · 2.65 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
title: "Untitled"
author: "yiyan Sun"
date: "2024-02-22"
output: html_document
---
```{r}
library(spatstat)
library(here)
library(sp)
library(rgeos)
library(maptools)
library(tmap)
library(tmaptools)
library(sf)
library(geojson)
library(geojsonio)
library(tmaptools)
library(stringr)
library(terra)
library(spgwr)
library(raster)
library(ggplot2)
```
```{r}
sensor <- read.csv("D:/CASApre/DataDive2024/MonitoringSiteSpecies.csv")
airquality <- read.csv("D:/CASApre/DataDive2024/merged_air_quality.csv")
waterloo <- read.csv("D:/CASApre/DataDive2024/Waterloo_CE2.csv")
```
```{r}
LSOA <- st_read("D:/CASApre/DataDive2024/ESRI/LSOA_2011_London_gen_MHW.shp") %>% st_transform(27700)
borough <- st_read("D:/CASApre/DataDive2024/ESRI/London_Borough_Excluding_MHW.shp") %>% st_transform(27700)
```
```{r}
qtm(borough)
```
```{r}
speed <- rast("D:/CASApre/DataDive2024/hourly_speed_data.tif")
hourly_speed_data_1 <- speed[[1]]
crs(hourly_speed_data_1) <- "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs"
plot(hourly_speed_data_1)
```
```{r}
join <- st_join(sensor, borough, join = st_intersects)
```
```{r}
speed2024 <- raster("D:/CASApre/DataDive2024/2024010100_3600_50.gtiff")
plot(speed2024)
```
```{r}
```
```{r}
```
```{r}
merged_data <- merge(borough, hourly_speed_data_1, join="left")
# Now merged_data contains the LSOA data with hourly_speed_data_1 values as a new column
```
```{r}
plot(merged_data)
```
```{r}
```
```{r}
# Create a scatter plot of sensor data with coordinates
ggplot(sensor, aes(x = Longitude, y = Latitude)) +
geom_point() +
labs(x = "Longitude", y = "Latitude", title = "Sensor Data Visualization")
```
```{r}
# Convert sensor data to sf object
sensor_sf <- st_as_sf(sensor, coords = c("Longitude", "Latitude"), crs = 4326)
# Transform coordinates to EPSG 27700 (British National Grid)
sensor_sf <- st_transform(sensor_sf, crs = 27700)
# Create a scatter plot of sensor data with transformed coordinates
ggplot(sensor_sf) +
geom_sf() +
labs(x = "Longitude (British National Grid)", y = "Latitude (British National Grid)", title = "Sensor Data Visualization (British National Grid)")
```
```{r}
# Check CRS of sensor data and LSOA data
print(st_crs(sensor_sf))
print(st_crs(LSOA))
# Transform sensor data to match the CRS of LSOA data
sensor_sf <- st_transform(sensor_sf, crs = st_crs(LSOA))
# Perform spatial join
joined_data <- st_join(sensor_sf, LSOA, join = st_intersects)
# View the joined data
print(joined_data)
```
```{r}
tmap_mode("plot")
tm_shape(LSOA) +
tm_polygons() +
tm_shape(sensor_sf)
```
```{r}
```