-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathrnet_breakup_vertices.Rd
123 lines (113 loc) · 4.99 KB
/
rnet_breakup_vertices.Rd
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rnet-clean.R
\name{rnet_breakup_vertices}
\alias{rnet_breakup_vertices}
\title{Break up an sf object with LINESTRING geometry.}
\usage{
rnet_breakup_vertices(rnet, verbose = FALSE)
}
\arguments{
\item{rnet}{An sf or sfc object with LINESTRING geometry representing a route
network.}
\item{verbose}{Boolean. If TRUE, the function prints additional messages.}
}
\value{
An sf or sfc object with LINESTRING geometry created after breaking
up the input object.
}
\description{
This function breaks up a LINESTRING geometry into multiple LINESTRING(s). It
is used mainly for preserving routability of an object that is
created using Open Street Map data. See details,
\href{https://github.com/ropensci/stplanr/issues/282}{stplanr/issues/282}, and
\href{https://github.com/ropensci/stplanr/issues/416}{stplanr/issues/416}.
}
\details{
A LINESTRING geometry is broken-up when one of the two following conditions
are met:
\enumerate{
\item two or more LINESTRINGS share a POINT which is a boundary point for some
LINESTRING(s), but not all of them (see the rnet_roundabout example);
\item two or more LINESTRINGS share a POINT which is not in the boundary of any
LINESTRING (see the rnet_cycleway_intersection example).
}
The problem with the first example is that, according to algorithm behind
\code{SpatialLinesNetwork()}, two LINESTRINGS are connected if and only if they
share at least one point in their boundaries. The roads and the roundabout
are clearly connected in the "real" world but the corresponding LINESTRING
objects do not share two distinct boundary points. In fact, by Open Street
Map standards, a roundabout is represented as a closed and circular
LINESTRING, and this implies that the roundabout is not connected to the
other roads according to \code{SpatialLinesNetwork()} definition. By the same
reasoning, the roads in the second example are clearly connected in the
"real" world, but they do not share any point in their boundaries. This
function is used to solve this type of problem.
}
\examples{
library(sf)
def_par <- par(no.readonly = TRUE)
par(mar = rep(0, 4))
# Check the geometry of the roundabout example. The dots represent the
# boundary points of the LINESTRINGS. The "isolated" red point in the
# top-left is the boundary point of the roundabout, and it is not shared
# with any other street.
plot(st_geometry(rnet_roundabout), lwd = 2, col = rainbow(nrow(rnet_roundabout)))
boundary_points <- st_geometry(line2points(rnet_roundabout))
points_cols <- rep(rainbow(nrow(rnet_roundabout)), each = 2)
plot(boundary_points, pch = 16, add = TRUE, col = points_cols, cex = 2)
# Clean the roundabout example.
rnet_roundabout_clean <- rnet_breakup_vertices(rnet_roundabout)
plot(st_geometry(rnet_roundabout_clean), lwd = 2, col = rainbow(nrow(rnet_roundabout_clean)))
boundary_points <- st_geometry(line2points(rnet_roundabout_clean))
points_cols <- rep(rainbow(nrow(rnet_roundabout_clean)), each = 2)
plot(boundary_points, pch = 16, add = TRUE, col = points_cols)
# The roundabout is now routable since it was divided into multiple pieces
# (one for each colour), which, according to SpatialLinesNetwork() function,
# are connected.
# Check the geometry of the overpasses example. This example is used to test
# that this function does not create any spurious intersection.
plot(st_geometry(rnet_overpass), lwd = 2, col = rainbow(nrow(rnet_overpass)))
boundary_points <- st_geometry(line2points(rnet_overpass))
points_cols <- rep(rainbow(nrow(rnet_overpass)), each = 2)
plot(boundary_points, pch = 16, add = TRUE, col = points_cols, cex = 2)
# At the moment the network is not routable since one of the underpasses is
# not connected to the other streets.
# Check interactively.
# mapview::mapview(rnet_overpass)
# Clean the network. It should not create any spurious intersection between
# roads located at different heights.
rnet_overpass_clean <- rnet_breakup_vertices(rnet_overpass)
plot(st_geometry(rnet_overpass_clean), lwd = 2, col = rainbow(nrow(rnet_overpass_clean)))
# Check interactively.
# mapview::mapview(rnet_overpass)
# Check the geometry of the cycleway_intersection example. The black dots
# represent the boundary points and we can see that the two roads are not
# connected according to SpatialLinesNetwork() function.
plot(
rnet_cycleway_intersection$geometry,
lwd = 2,
col = rainbow(nrow(rnet_cycleway_intersection)),
cex = 2
)
plot(st_geometry(line2points(rnet_cycleway_intersection)), pch = 16, add = TRUE)
# Check interactively
# mapview::mapview(rnet_overpass)
# Clean the rnet object and plot the result.
rnet_cycleway_intersection_clean <- rnet_breakup_vertices(rnet_cycleway_intersection)
plot(
rnet_cycleway_intersection_clean$geometry,
lwd = 2,
col = rainbow(nrow(rnet_cycleway_intersection_clean)),
cex = 2
)
plot(st_geometry(line2points(rnet_cycleway_intersection_clean)), pch = 16, add = TRUE)
par(def_par)
}
\seealso{
Other rnet:
\code{\link{gsection}()},
\code{\link{islines}()},
\code{\link{overline}()},
\code{\link{rnet_group}()}
}
\concept{rnet}