Title: | Homogenous Segmentation for Spatial Lines Data |
---|---|
Description: | Methods of homogenous segmentation for spatial lines data, such as pavement performance indicators and traffic volumes. Three methods are available for homogenous segmentation, including cumulative difference approach, minimization coefficient of variation, and spatial heterogeneity based method. |
Authors: | Yongze Song [aut, cre] |
Maintainer: | Yongze Song <[email protected]> |
License: | GPL-2 |
Version: | 1.1 |
Built: | 2024-08-27 07:27:47 UTC |
Source: | https://github.com/cranhaven/cranhaven.r-universe.dev |
Function for homogeneous segmentation of spatial lines data using a cummulative difference approach (CDA).
cda(var = "deflection", length = "length", data, range = NULL)
cda(var = "deflection", length = "length", data, range = NULL)
var |
A character or a character vector of variable names, such as a road pavement performance indicator. |
length |
A character of road length name in data. |
data |
A data frame of a dataset. |
range |
A vector of length threshold. |
testdata <- tsdwa[1:100,] testdata$Length <- testdata$SLK.end - testdata$SLK.start testdata <- cda(var = "Deflection", length = "Length", testdata)
testdata <- tsdwa[1:100,] testdata$Length <- testdata$SLK.end - testdata$SLK.start testdata <- cda(var = "Deflection", length = "Length", testdata)
The "deflection" dataset is a sample of the road deflection data monitored and collected by Main Roads Western Australia.
deflection
deflection
deflection
: A data frame with 1000 rows and 4 variables.
id. Number of observation.
SLK.start. Spatial start location of data. SLK is short for the straight line kilometer.
SLK.end. Spatial end location of data.
Deflection. The monitored road deflection value.
Yongze Song [email protected]
Find spaital breaking locations and add a column of breaks.
findbreak(start = "SLK.start", end = "SLK.end", data, dist.allow = 0.05, line.no = NULL)
findbreak(start = "SLK.start", end = "SLK.end", data, dist.allow = 0.05, line.no = NULL)
start |
A character of start location name of a spatial line. |
end |
A character of end location name of a spatial line. |
data |
A data frame of a dataset. |
dist.allow |
A number of the maximum allowed breaks within a line segment. |
line.no |
A character of spatial line name. |
testdata <- tsdwa[1:100,] testdata <- findbreak(start = "SLK.start", end = "SLK.end", data = testdata, dist.allow = 0.05)
testdata <- tsdwa[1:100,] testdata <- findbreak(start = "SLK.start", end = "SLK.end", data = testdata, dist.allow = 0.05)
Homogeneous segmentation function with continuous variables.
hs(start = "SLK.start", end = "SLK.end", var = "deflection", data, method = "shs", range = NULL)
hs(start = "SLK.start", end = "SLK.end", var = "deflection", data, method = "shs", range = NULL)
start |
A character of start location name of a spatial line. |
end |
A character of end location name of a spatial line. |
var |
A character or a character vector of variable names, such as a road pavement performance indicator. |
data |
A data frame of a dataset. |
method |
A character of homogeneous segmentation method. Available methods include "shs", "cda" and "mcv". |
range |
A vector of segment length threshold. |
testdata <- tsdwa[1:100,] hs1 <- hs(start = "SLK.start", end = "SLK.end", var = c("Curvature", "Deflection", "BLI"), testdata, method = "shs", range = c(0.1, 0.5))
testdata <- tsdwa[1:100,] hs1 <- hs(start = "SLK.start", end = "SLK.end", var = c("Curvature", "Deflection", "BLI"), testdata, method = "shs", range = c(0.1, 0.5))
Homogeneous segmentation function with both categorical and continous variables.
hsctg(start = "SLK.start", end = "SLK.end", var = "deflection", data, method = "shs", range = NULL, by.ctg = NULL)
hsctg(start = "SLK.start", end = "SLK.end", var = "deflection", data, method = "shs", range = NULL, by.ctg = NULL)
start |
A character of start location name of a spatial line. |
end |
A character of end location name of a spatial line. |
var |
A character or a character vector of variable names, such as a road pavement performance indicator. |
data |
A data frame of a dataset. |
method |
A character of homogeneous segmentation method. Available methods include "shs", "cda" and "mcv". |
range |
A vector of segment length threshold. |
by.ctg |
A vector of categorical variable names. |
testdata <- tsdwa[1:300,] hc1 <- hsctg(start = "SLK.start", end = "SLK.end", var = c("Curvature", "Deflection", "BLI"), testdata, method = "shs", range = c(0.1, 0.5), by.ctg = c("SurfType", "PvtType"))
testdata <- tsdwa[1:300,] hc1 <- hsctg(start = "SLK.start", end = "SLK.end", var = c("Curvature", "Deflection", "BLI"), testdata, method = "shs", range = c(0.1, 0.5), by.ctg = c("SurfType", "PvtType"))
Minimization coefficient of variation (MCV) for homogeneous segmentation of spatial lines data.
mcv(var = "deflection", length = "length", data, range = NULL)
mcv(var = "deflection", length = "length", data, range = NULL)
var |
A character or a character vector of variable names, such as a road pavement performance indicator. |
length |
A character of road length name in data. |
data |
A data frame of a dataset. |
range |
A vector of segment length threshold. |
testdata <- tsdwa[1:100,] testdata$length <- testdata$SLK.end - testdata$SLK.start testdata <- mcv(var = "Deflection", length = "length", testdata, range = c(0.1, 0.5))
testdata <- tsdwa[1:100,] testdata$length <- testdata$SLK.end - testdata$SLK.start testdata <- mcv(var = "Deflection", length = "length", testdata, range = c(0.1, 0.5))
The preprocessing includes two steps: removing missing data and ordering data by spatial locations.
preprocessing(var = "deflection", location = "SLK", data = data)
preprocessing(var = "deflection", location = "SLK", data = data)
var |
A character of the name of a variable in a dataset, such as a road pavement performance indicator. |
location |
A character of the name of spatial locations in a dataset. |
data |
A data frame of monitoring data. |
testdata <- tsdwa[1:100,] testdata <- preprocessing(var = "Deflection", location = "SLK.start", data = testdata)
testdata <- tsdwa[1:100,] testdata <- preprocessing(var = "Deflection", location = "SLK.start", data = testdata)
Segmentation with categorical variables.
segbycategory(data, by = NULL)
segbycategory(data, by = NULL)
data |
A data frame of a dataset. |
by |
A character or a vector of categorical variable names. |
testdata <- tsdwa[1:100,] testdata <- segbycategory(testdata, by = c("SurfType", "PvtType"))
testdata <- tsdwa[1:100,] testdata <- segbycategory(testdata, by = c("SurfType", "PvtType"))
Segments comparison of different homogeneous segmentations methods.
segcompare(start = "SLK.start", end = "SLK.end", var = "deflection", data, segid.matrix, methods = NULL) ## S3 method for class 'segcompare' print(x, ...) ## S3 method for class 'segcompare' plot(x, ...)
segcompare(start = "SLK.start", end = "SLK.end", var = "deflection", data, segid.matrix, methods = NULL) ## S3 method for class 'segcompare' print(x, ...) ## S3 method for class 'segcompare' plot(x, ...)
start |
A character of start location name of a spatial line. |
end |
A character of end location name of a spatial line. |
var |
A character or a character vector of variable names, such as a road pavement performance indicator. |
data |
A list of segmentation result. |
segid.matrix |
A matrix of segmentations. |
methods |
A vector of segmentation method names, default NULL. |
x |
A list of segments comparison result. |
... |
Ignore |
testdata <- tsdwa[1:300, ] testdata$length <- testdata$SLK.end - testdata$SLK.start variable <- c("Curvature", "Deflection", "BLI") seg1 <- hs(start = "SLK.start", end = "SLK.end", var = variable, testdata, method = "shs", range = c(0.1, 0.5)) # 0.3 s seg2 <- hs(start = "SLK.start", end = "SLK.end", var = variable, testdata, method = "cda", range = c(0.1, 0.5)) # 0.7 s seg3 <- hs(start = "SLK.start", end = "SLK.end", var = variable, testdata, method = "mcv", range = c(0.1, 0.5)) # 0.6 s segid.matrix <- cbind(seg1$seg.id, seg2$seg.id, seg3$seg.id) data(segid.matrix) cp <- segcompare(start = "SLK.start", end = "SLK.end", var = variable, testdata, segid.matrix, methods = c("SHS", "CDA", "MCV")) # 4.8 s cp plot(cp)
testdata <- tsdwa[1:300, ] testdata$length <- testdata$SLK.end - testdata$SLK.start variable <- c("Curvature", "Deflection", "BLI") seg1 <- hs(start = "SLK.start", end = "SLK.end", var = variable, testdata, method = "shs", range = c(0.1, 0.5)) # 0.3 s seg2 <- hs(start = "SLK.start", end = "SLK.end", var = variable, testdata, method = "cda", range = c(0.1, 0.5)) # 0.7 s seg3 <- hs(start = "SLK.start", end = "SLK.end", var = variable, testdata, method = "mcv", range = c(0.1, 0.5)) # 0.6 s segid.matrix <- cbind(seg1$seg.id, seg2$seg.id, seg3$seg.id) data(segid.matrix) cp <- segcompare(start = "SLK.start", end = "SLK.end", var = variable, testdata, segid.matrix, methods = c("SHS", "CDA", "MCV")) # 4.8 s cp plot(cp)
Segmentation results of CDA, MCV and SHS methods for data "tsdwa".
segid.matrix
segid.matrix
segid.matrix
: A matrix with 300 rows and 3 columes,
representing segmentations of three methods, CDA, MCV and SHS.
Yongze Song [email protected]
Visualization of homogeneous segments.
segplot(start = "SLK.start", var = "deflection", seg.id = "seg.id", data, plot.range = NULL)
segplot(start = "SLK.start", var = "deflection", seg.id = "seg.id", data, plot.range = NULL)
start |
A character of start location name of a spatial line. |
var |
A character or a character vector of variable names, such as a road pavement performance indicator. |
seg.id |
A character of the name of new segment number. |
data |
A data frame of a dataset. |
plot.range |
A vector of plot range. |
testdata <- tsdwa[1:300,] testdata$length <- testdata$SLK.end - testdata$SLK.start testdata <- shs(var = c("Curvature", "Deflection"), length = "length", testdata, range = c(0.1, 0.5)) segplot(start = "SLK.start", var = c("Curvature", "Deflection"), seg.id = "seg.id", testdata, plot.range = 1:300)
testdata <- tsdwa[1:300,] testdata$length <- testdata$SLK.end - testdata$SLK.start testdata <- shs(var = c("Curvature", "Deflection"), length = "length", testdata, range = c(0.1, 0.5)) segplot(start = "SLK.start", var = c("Curvature", "Deflection"), seg.id = "seg.id", testdata, plot.range = 1:300)
A center aligned moving window is used for the moving average method.
segsmooth(var = "deflection", range = 11, data)
segsmooth(var = "deflection", range = 11, data)
var |
A character of the name of a variable in a dataset, such as a road pavement performance indicator. |
range |
A number of the size of moving window. An odd number is required. |
data |
A data frame of monitoring data. |
# preprocessing testdata <- tsdwa[1:500,] testdata <- preprocessing(var = "Deflection", location = "SLK.start", data = testdata) # smoothing testdata <- segsmooth(var = "Deflection", range = 11, data = testdata) # plot plot(testdata$SLK.start, testdata$Deflection, type = "l", col = "lightblue", xlab = "location", ylab = "deflection") lines(testdata$SLK.start, testdata$smooth.Deflection)
# preprocessing testdata <- tsdwa[1:500,] testdata <- preprocessing(var = "Deflection", location = "SLK.start", data = testdata) # smoothing testdata <- segsmooth(var = "Deflection", range = 11, data = testdata) # plot plot(testdata$SLK.start, testdata$Deflection, type = "l", col = "lightblue", xlab = "location", ylab = "deflection") lines(testdata$SLK.start, testdata$smooth.Deflection)
Statistical summary of homogeneous segments.
segsummary(start = "SLK.start", end = "SLK.end", var = "deflection", seg.id = "seg.id", data, by.ctg = NULL) ## S3 method for class 'segsummary' print(x, ...)
segsummary(start = "SLK.start", end = "SLK.end", var = "deflection", seg.id = "seg.id", data, by.ctg = NULL) ## S3 method for class 'segsummary' print(x, ...)
start |
A character of start location name of a spatial line. |
end |
A character of end location name of a spatial line. |
var |
A character or a character vector of variable names, such as a road pavement performance indicator. |
seg.id |
A character of the name of new segment number. |
data |
A data frame of a dataset. |
by.ctg |
A character of categorical variable names. |
x |
A list of segmentation result. |
... |
Ignore |
testdata <- tsdwa[1:100,] testdata$length <- testdata$SLK.end - testdata$SLK.start testdata <- shs(var = c("Curvature", "Deflection"), length = "length", testdata, range = c(0.1, 0.5)) s1 <- segsummary(start = "SLK.start", end = "SLK.end", var = c("Curvature", "Deflection"), seg.id = "seg.id", testdata) s1
testdata <- tsdwa[1:100,] testdata$length <- testdata$SLK.end - testdata$SLK.start testdata <- shs(var = c("Curvature", "Deflection"), length = "length", testdata, range = c(0.1, 0.5)) s1 <- segsummary(start = "SLK.start", end = "SLK.end", var = c("Curvature", "Deflection"), seg.id = "seg.id", testdata) s1
Spatial heterogeneity-based segmentation (SHS) for homogeneous segmentation of spatial lines data.
shs(var = "deflection", length = "length", data, range = NULL)
shs(var = "deflection", length = "length", data, range = NULL)
var |
A character or a character vector of variable names, such as a road pavement performance indicator. |
length |
A character of road length name in data. |
data |
A data frame of a dataset. |
range |
A vector of segment length threshold. |
testdata <- tsdwa[1:100,] testdata$length <- testdata$SLK.end - testdata$SLK.start testdata <- shs(var = "Deflection", length = "length", testdata, range = c(0.1, 0.5))
testdata <- tsdwa[1:100,] testdata$length <- testdata$SLK.end - testdata$SLK.start testdata <- shs(var = "Deflection", length = "length", testdata, range = c(0.1, 0.5))
Split long segments to segments within length threshold.
splitlong(var = "deflection", length = "length", seg.id = "seg.id", data, range = NULL)
splitlong(var = "deflection", length = "length", seg.id = "seg.id", data, range = NULL)
var |
A character or a character vector of variable names, such as a road pavement performance indicator. |
length |
A character of length name. |
seg.id |
A character of the name of new segment number. |
data |
A data frame of a dataset. |
range |
A vector of segment length threshold. |
testdata <- tsdwa[1:1000,] testdata$length <- round(testdata$SLK.end - testdata$SLK.start, digits = 10) testdata <- cda(var = "Deflection", length = "length", testdata, range = c(0.1, 0.5)) testdata <- splitlong(var = "Deflection", length = "length", seg.id = "seg.id", testdata, range = c(0.1, 0.5)) seglength.summary <- testdata[, .(sum(length)), by = .(seg.id)]
testdata <- tsdwa[1:1000,] testdata$length <- round(testdata$SLK.end - testdata$SLK.start, digits = 10) testdata <- cda(var = "Deflection", length = "length", testdata, range = c(0.1, 0.5)) testdata <- splitlong(var = "Deflection", length = "length", seg.id = "seg.id", testdata, range = c(0.1, 0.5)) seglength.summary <- testdata[, .(sum(length)), by = .(seg.id)]
The "tsdwa" dataset is a sample of the pavement deterioration data monitored and collected by Main Roads Western Australia.
tsdwa
tsdwa
tsdwa
: A data frame with 5000 rows and 8 variables.
id. Number of observation.
SLK.start. Spatial start location of data. SLK is short for the straight line kilometer.
SLK.end. Spatial end location of data.
SurfType. Surfacing type.
PvtType. Pavement type.
Curvature.
Deflection.
BLI. Base layer index.
Yongze Song [email protected]