-
Notifications
You must be signed in to change notification settings - Fork 1
/
Spatial_polyline_analysis.R
296 lines (251 loc) · 14.9 KB
/
Spatial_polyline_analysis.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
library(dggridR)
library(rgdal)
library(geosphere)
library(plotrix)
library(ggplot2)
library(gridExtra)
library(dplyr)
library(tidyverse)
# create a vector to store tested tested orientation
azimuth = seq(-90,90,by=15)
# create empty dataframes
ISEA3H24.stats.df = ISEA3H25.stats.df = ISEA3H26.stats.df = ISEA3H27.stats.df = ISEA3H28.stats.df =
ISEA4H18.stats.df = ISEA4H19.stats.df = ISEA4H20.stats.df = ISEA4H21.stats.df = ISEA4H22.stats.df =
ISEA4T17.stats.df = ISEA4T18.stats.df = ISEA4T19.stats.df = ISEA4T20.stats.df = ISEA4T21.stats.df =
ISEA4D18.stats.df = ISEA4D19.stats.df = ISEA4D20.stats.df = ISEA4D21.stats.df = ISEA4D22.stats.df =
data.frame(Azimuth = integer(),Resolution = integer(),Orig.length = double(),Convert.length = double(),
Delta.length = double(),Delta.length.abs = double(),Delta.length.pct = double())
## Create a function to return the transformed vertex lat/lon
cell.convert = function(azimuthdeg,proj,aperture,topology,res,input.df) {
# Construct a dgg object
DGG = dgconstruct(proj, aperture, topology, res, precision = 7,
azimuth_deg = 0, pole_lat_deg = azimuthdeg, pole_lon_deg = 11.25)
# Convert the lat&lon of points to corresponding linear address of grid cells
Cell_address = dgGEO_to_SEQNUM(DGG,input.df$lon,input.df$lat)$seqnum
# Convert the linear address of grid cells to lat&lon which are the center coordinates of the cells
Cellcenter_lon = dgSEQNUM_to_GEO(DGG,Cell_address)$lon_deg
Cellcenter_lat = dgSEQNUM_to_GEO(DGG,Cell_address)$lat_deg
input.df$CellAddress = Cell_address
input.df$Cellcenter_lon = Cellcenter_lon
input.df$Cellcenter_lat = Cellcenter_lat
input.df$res = rep(res, nrow(input.df))
input.df$azimuth = rep(azimuthdeg, nrow(input.df))
input.df = input.df[!duplicated(input.df$CellAddress),]
return(input.df)
}
## Create a function to calculate the line length in the converted dggs grids, along with some stats
polyline.length = function(azimuthdeg,input.df,res){
input.df = filter(input.df,azimuth == azimuthdeg)
streetvertex.convert.matrix = input.df[,c("Cellcenter_lon","Cellcenter_lat")]
# Calculate the original length and the length after convension
Orig.length = 527.9683
Convert.length = lengthLine(streetvertex.convert.matrix)
# Calculate some stats
Delta.length = Orig.length - Convert.length
Delta.length.abs = abs(Delta.length)
Delta.length.pct = Delta.length.abs/Orig.length
results = c(azimuthdeg,res,Orig.length,Convert.length,Delta.length,Delta.length.abs,Delta.length.pct)
return(results)
}
## ISEA3H28 ISEA4H22 ISEA4D22 ##
# Read point datasets
StreetsVertex = read.csv("Result/Split_points_05m.csv")[ ,c('ORIG_FID', 'lat','lon')]
StreetsVertex = filter(StreetsVertex,ORIG_FID == 29)
# Invoke the function in a loop of street ID
ISEA3H28.df = ISEA4H22.df = ISEA4D22.df = StreetsVertex[FALSE,]
for(a in azimuth) {
ISEA3H28.df = rbind(ISEA3H28.df, cell.convert(a,"ISEA",3,"HEXAGON",28,StreetsVertex))
ISEA4H22.df = rbind(ISEA4H22.df, cell.convert(a,"ISEA",4,"HEXAGON",22,StreetsVertex))
ISEA4D22.df = rbind(ISEA4D22.df, cell.convert(a,"ISEA",4,"DIAMOND",22,StreetsVertex))
}
for(a in azimuth) {
ISEA3H28.stats.df = rbind(ISEA3H28.stats.df, polyline.length(a,ISEA3H28.df,28))
ISEA4H22.stats.df = rbind(ISEA4H22.stats.df, polyline.length(a,ISEA4H22.df,22))
ISEA4D22.stats.df = rbind(ISEA4D22.stats.df, polyline.length(a,ISEA4D22.df,22))
}
# Rename the fields
names(ISEA3H28.stats.df) = names(ISEA4H22.stats.df) = names(ISEA4D22.stats.df) =
c("Azimuth","Resolution","OrigLength","ConvertLength","DeltaLength","DeltaLengthABS","DeltaLengthPCT")
## ISEA3H27 ISEA4T21 ##
# Read point datasets
StreetsVertex = read.csv("Result/Split_points_1m.csv")[ ,c('ORIG_FID', 'lat','lon')]
StreetsVertex = filter(StreetsVertex,ORIG_FID == 29)
# Invoke the function in a loop of street ID
ISEA3H27.df = ISEA4T21.df = StreetsVertex[FALSE,]
for(a in azimuth) {
ISEA3H27.df = rbind(ISEA3H27.df, cell.convert(a,"ISEA",3,"HEXAGON",27,StreetsVertex))
ISEA4T21.df = rbind(ISEA4T21.df, cell.convert(a,"ISEA",4,"TRIANGLE",21,StreetsVertex))
}
for(a in azimuth) {
ISEA3H27.stats.df = rbind(ISEA3H27.stats.df, polyline.length(a,ISEA3H27.df,27))
ISEA4T21.stats.df = rbind(ISEA4T21.stats.df, polyline.length(a,ISEA4T21.df,21))
}
# Rename the fields
names(ISEA3H27.stats.df) = names(ISEA4T21.stats.df) =
c("Azimuth","Resolution","OrigLength","ConvertLength","DeltaLength","DeltaLengthABS","DeltaLengthPCT")
## ISEA4H21 ISEA4D21 ISEA4T20 ##
# Read point datasets
StreetsVertex = read.csv("Result/Split_points_1-5m.csv")[ ,c('ORIG_FID', 'lat','lon')]
StreetsVertex = filter(StreetsVertex,ORIG_FID == 29)
# Invoke the function in a loop of street ID
ISEA4H21.df = ISEA4D21.df = ISEA4T20.df = StreetsVertex[FALSE,]
for(a in azimuth) {
ISEA4H21.df = rbind(ISEA4H21.df, cell.convert(a,"ISEA",4,"HEXAGON",21,StreetsVertex))
ISEA4D21.df = rbind(ISEA4D21.df, cell.convert(a,"ISEA",4,"DIAMOND",21,StreetsVertex))
ISEA4T20.df = rbind(ISEA4T20.df, cell.convert(a,"ISEA",4,"TRIANGLE",20,StreetsVertex))
}
for(a in azimuth) {
ISEA4H21.stats.df = rbind(ISEA4H21.stats.df, polyline.length(a,ISEA4H21.df,21))
ISEA4D21.stats.df = rbind(ISEA4D21.stats.df, polyline.length(a,ISEA4D21.df,21))
ISEA4T20.stats.df = rbind(ISEA4T20.stats.df, polyline.length(a,ISEA4T20.df,20))
}
# Rename the fields
names(ISEA4H21.stats.df) = names(ISEA4D21.stats.df) = names(ISEA4T20.stats.df) =
c("Azimuth","Resolution","OrigLength","ConvertLength","DeltaLength","DeltaLengthABS","DeltaLengthPCT")
## ISEA3H26 ##
# Read point datasets
StreetsVertex = read.csv("Result/Split_points_2m.csv")[ ,c('ORIG_FID', 'lat','lon')]
StreetsVertex = filter(StreetsVertex,ORIG_FID == 29)
# Invoke the function in a loop of street ID
ISEA3H26.df = StreetsVertex[FALSE,]
for(a in azimuth) {
ISEA3H26.df = rbind(ISEA3H26.df, cell.convert(a,"ISEA",3,"HEXAGON",26,StreetsVertex))
}
for(a in azimuth) {
ISEA3H26.stats.df = rbind(ISEA3H26.stats.df, polyline.length(a,ISEA3H26.df,26))
}
# Rename the fields
names(ISEA3H26.stats.df) =
c("Azimuth","Resolution","OrigLength","ConvertLength","DeltaLength","DeltaLengthABS","DeltaLengthPCT")
## ISEA3H25 ISEA4H20 ISEA4D20 ISEA4T19 ##
# Read point datasets
StreetsVertex = read.csv("Result/Split_points_3m.csv")[ ,c('ORIG_FID', 'lat','lon')]
StreetsVertex = filter(StreetsVertex,ORIG_FID == 29)
# Invoke the function in a loop of street ID
ISEA3H25.df = ISEA4H20.df = ISEA4D20.df = ISEA4T19.df = StreetsVertex[FALSE,]
for(a in azimuth) {
ISEA3H25.df = rbind(ISEA3H25.df, cell.convert(a,"ISEA",3,"HEXAGON",25,StreetsVertex))
ISEA4H20.df = rbind(ISEA4H20.df, cell.convert(a,"ISEA",4,"HEXAGON",20,StreetsVertex))
ISEA4D20.df = rbind(ISEA4D20.df, cell.convert(a,"ISEA",4,"DIAMOND",20,StreetsVertex))
ISEA4T19.df = rbind(ISEA4T19.df, cell.convert(a,"ISEA",4,"TRIANGLE",19,StreetsVertex))
}
for(a in azimuth) {
ISEA3H25.stats.df = rbind(ISEA3H25.stats.df, polyline.length(a,ISEA3H25.df,25))
ISEA4H20.stats.df = rbind(ISEA4H20.stats.df, polyline.length(a,ISEA4H20.df,20))
ISEA4D20.stats.df = rbind(ISEA4D20.stats.df, polyline.length(a,ISEA4D20.df,20))
ISEA4T19.stats.df = rbind(ISEA4T19.stats.df, polyline.length(a,ISEA4T19.df,19))
}
# Rename the fields
names(ISEA3H25.stats.df) = names(ISEA4H20.stats.df) = names(ISEA4D20.stats.df) = names(ISEA4T19.stats.df) =
c("Azimuth","Resolution","OrigLength","ConvertLength","DeltaLength","DeltaLengthABS","DeltaLengthPCT")
## ISEA3H24 ISEA4H19 ISEA4D19 ##
# Read point datasets
StreetsVertex = read.csv("Result/Split_points_6m.csv")[ ,c('ORIG_FID', 'lat','lon')]
StreetsVertex = filter(StreetsVertex,ORIG_FID == 29)
# Invoke the function in a loop of street ID
ISEA3H24.df = ISEA4H19.df = ISEA4D19.df = StreetsVertex[FALSE,]
for(a in azimuth) {
ISEA3H24.df = rbind(ISEA3H24.df, cell.convert(a,"ISEA",3,"HEXAGON",24,StreetsVertex))
ISEA4H19.df = rbind(ISEA4H19.df, cell.convert(a,"ISEA",4,"HEXAGON",19,StreetsVertex))
ISEA4D19.df = rbind(ISEA4D19.df, cell.convert(a,"ISEA",4,"DIAMOND",19,StreetsVertex))
}
for(a in azimuth) {
ISEA3H24.stats.df = rbind(ISEA3H24.stats.df, polyline.length(a,ISEA3H24.df,24))
ISEA4H19.stats.df = rbind(ISEA4H19.stats.df, polyline.length(a,ISEA4H19.df,19))
ISEA4D19.stats.df = rbind(ISEA4D19.stats.df, polyline.length(a,ISEA4D19.df,19))
}
# Rename the fields
names(ISEA3H24.stats.df) = names(ISEA4H19.stats.df) = names(ISEA4D19.stats.df) =
c("Azimuth","Resolution","OrigLength","ConvertLength","DeltaLength","DeltaLengthABS","DeltaLengthPCT")
## ISEA4T18 ##
# Read point datasets
StreetsVertex = read.csv("Result/Split_points_7m.csv")[ ,c('ORIG_FID', 'lat','lon')]
StreetsVertex = filter(StreetsVertex,ORIG_FID == 29)
# Invoke the function in a loop of street ID
ISEA4T18.df = StreetsVertex[FALSE,]
for(a in azimuth) {
ISEA4T18.df = rbind(ISEA4T18.df, cell.convert(a,"ISEA",4,"TRIANGLE",18,StreetsVertex))
}
for(a in azimuth) {
ISEA4T18.stats.df = rbind(ISEA4T18.stats.df, polyline.length(a,ISEA4T18.df,18))
}
# Rename the fields
names(ISEA4T18.stats.df) =
c("Azimuth","Resolution","OrigLength","ConvertLength","DeltaLength","DeltaLengthABS","DeltaLengthPCT")
## ISEA4H18 ISEA4D18 ISEA4T17 ##
# Read point datasets
StreetsVertex = read.csv("Result/Split_points_13m.csv")[ ,c('ORIG_FID', 'lat','lon')]
StreetsVertex = filter(StreetsVertex,ORIG_FID == 29)
# Invoke the function in a loop of street ID
ISEA4H18.df = ISEA4D18.df = ISEA4T17.df = StreetsVertex[FALSE,]
for(a in azimuth) {
ISEA4H18.df = rbind(ISEA4H18.df, cell.convert(a,"ISEA",4,"HEXAGON",18,StreetsVertex))
ISEA4D18.df = rbind(ISEA4D18.df, cell.convert(a,"ISEA",4,"DIAMOND",18,StreetsVertex))
ISEA4T17.df = rbind(ISEA4T17.df, cell.convert(a,"ISEA",4,"TRIANGLE",17,StreetsVertex))
}
for(a in azimuth) {
ISEA4H18.stats.df = rbind(ISEA4H18.stats.df, polyline.length(a,ISEA4H18.df,18))
ISEA4D18.stats.df = rbind(ISEA4D18.stats.df, polyline.length(a,ISEA4D18.df,18))
ISEA4T17.stats.df = rbind(ISEA4T17.stats.df, polyline.length(a,ISEA4T17.df,17))
}
# Rename the fields
names(ISEA4H18.stats.df) = names(ISEA4D18.stats.df) = names(ISEA4T17.stats.df) =
c("Azimuth","Resolution","OrigLength","ConvertLength","DeltaLength","DeltaLengthABS","DeltaLengthPCT")
## Visualize the results
ISEA3H.df = rbind(ISEA3H24.stats.df,ISEA3H25.stats.df,ISEA3H26.stats.df,ISEA3H27.stats.df,ISEA3H28.stats.df)
ISEA4H.df = rbind(ISEA4H18.stats.df,ISEA4H19.stats.df,ISEA4H20.stats.df,ISEA4H21.stats.df,ISEA4H22.stats.df)
ISEA4T.df = rbind(ISEA4T17.stats.df,ISEA4T18.stats.df,ISEA4T19.stats.df,ISEA4T20.stats.df,ISEA4T21.stats.df)
ISEA4D.df = rbind(ISEA4D18.stats.df,ISEA4D19.stats.df,ISEA4D20.stats.df,ISEA4D21.stats.df,ISEA4D22.stats.df)
ISEA3H.plot = ggplot(data = ISEA3H.df, aes(x = Azimuth, y = DeltaLengthABS)) +
geom_line(aes(group = Resolution,colour = factor(Resolution)),size=1.5) +
scale_y_continuous(name = "Absolute Delta Length (m)",
breaks = seq(0, 120, by = 20),limits=c(0, 125)) +
scale_x_continuous(name = "Latitude of the pole (°)",
breaks = seq(-90, 90, by = 15),limits=c(-91, 91)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(),
legend.position="top", text=element_text(size = 14),plot.title=element_text(face="bold",size=14,hjust = 0.5),
axis.title = element_text(face="bold"), axis.line = element_line(colour = "black",size = 1),
axis.text.x=element_text(size = 12, face="bold", colour = "black"),
axis.text.y=element_text(size = 12, face="bold", colour = "black"),
legend.title = element_text(colour="black", size=12, face="bold"),
legend.text = element_text(colour="black", size=12, face="bold"))
ISEA4H.plot = ggplot(data = ISEA4H.df, aes(x = Azimuth, y = DeltaLengthABS)) +
geom_line(aes(group = Resolution,colour = factor(Resolution)),size=1.5) +
scale_y_continuous(name = "Absolute Delta Length (m)",
breaks = seq(0, 140, by = 20),limits=c(0, 140)) +
scale_x_continuous(name = "Latitude of the pole (°)",
breaks = seq(-90, 90, by = 15),limits=c(-91, 91)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(),
legend.position="top", text=element_text(size = 14),plot.title=element_text(face="bold",size=14,hjust = 0.5),
axis.title = element_text(face="bold"), axis.line = element_line(colour = "black",size = 1),
axis.text.x=element_text(size = 12, face="bold", colour = "black"),
axis.text.y=element_text(size = 12, face="bold", colour = "black"),
legend.title = element_text(colour="black", size=12, face="bold"),
legend.text = element_text(colour="black", size=12, face="bold"))
ISEA4T.plot = ggplot(data = ISEA4T.df, aes(x = Azimuth, y = DeltaLengthABS)) +
geom_line(aes(group = Resolution,colour = factor(Resolution)),size=1.5) +
scale_y_continuous(name = "Absolute Delta Length (m)",
breaks = seq(0, 180, by = 20),limits=c(0, 180)) +
scale_x_continuous(name = "Latitude of the pole (°)",
breaks = seq(-90, 90, by = 15),limits=c(-91, 91)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(),
legend.position="top", text=element_text(size = 14),plot.title=element_text(face="bold",size=14,hjust = 0.5),
axis.title = element_text(face="bold"), axis.line = element_line(colour = "black",size = 1),
axis.text.x=element_text(size = 12, face="bold", colour = "black"),
axis.text.y=element_text(size = 12, face="bold", colour = "black"),
legend.title = element_text(colour="black", size=12, face="bold"),
legend.text = element_text(colour="black", size=12, face="bold"))
ISEA4D.plot = ggplot(data = ISEA4D.df, aes(x = Azimuth, y = DeltaLengthABS)) +
geom_line(aes(group = Resolution,colour = factor(Resolution)),size=1.5) +
scale_y_continuous(name = "Absolute Delta Length (m)",
breaks = seq(0, 280, by = 40),limits=c(0, 280)) +
scale_x_continuous(name = "Latitude of the pole (°)",
breaks = seq(-90, 90, by = 15),limits=c(-91, 91)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(),
legend.position="top", text=element_text(size = 14),plot.title=element_text(face="bold",size=14,hjust = 0.5),
axis.title = element_text(face="bold"), axis.line = element_line(colour = "black",size = 1),
axis.text.x=element_text(size = 12, face="bold", colour = "black"),
axis.text.y=element_text(size = 12, face="bold", colour = "black"),
legend.title = element_text(colour="black", size=12, face="bold"),
legend.text = element_text(colour="black", size=12, face="bold"))
grid.arrange(ISEA3H.plot, ISEA4H.plot, ISEA4T.plot, ISEA4D.plot, nrow=2)