forked from ayushikachhara/NO2_TrafficImpactModelling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrafficbuffers.R
69 lines (59 loc) · 1.64 KB
/
Trafficbuffers.R
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
#### creating buffers for all traffic data ####
## import libraries ##
library(librarian)
shelf(data.table,
ggplot2,
zoo,
dplyr,
gridExtra,
grid,
plotly,
RColorBrewer,
statsr,
dplyr,
pracma,
openair,
mapplots,
mapview,
leaflet,
rgdal,
sp,
raster,
rgeos,
lubridate,
tidyr,
sf,
lib = tempdir())
## import traffic files##
path = "S:/kachharaa/NO2 spatial modelling/traffic_data/NZTA_traffic/"
listoffiles <- list.files(path = path, pattern = "*.shp")
## calculate buffer columns ###
listNZTA <- list()
k = 1
for(i in 1:length(listoffiles)) {
tryCatch({
f1 <- readOGR(paste0(path,listoffiles[[(i)]]))
## creating buffer that reduces NO2 to 2
f1$AADT_cal2 <- ifelse(f1$trafficVol<8000, 8000, f1$trafficVol)
f1$buffer2 <- 66.7*log(f1$AADT_cal2) - 596
print(i)
listNZTA[[k]] <- f1
k = k+1
}, error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
}
## apply buffer and create an output of buffer shapes ####
setwd("S:/kachharaa/NO2 spatial modelling/traffic_data/trafficBuffers/")
bufferlist <- list()
i = 1
for(i in 1:length(listNZTA)) {
f1 <- listNZTA[[i]]
buff1 <- gUnaryUnion(gBuffer(f1,width = f1$buffer2, byid = TRUE))
buff1 <- SpatialPolygonsDataFrame(buff1, data.frame(FID=as.numeric(1)))
plot(buff1)
bufferlist[[i]] <- buff1
nameoffile <- unlist(strsplit(listoffiles[i], ".shp"))
nameoffile <-paste0(nameoffile, "_buffer")
writeOGR(buff1, ".",nameoffile, "ESRI Shapefile",
overwrite_layer = T)
print(i)
}