Title: | Analyzing Spatial Events on Roadways |
---|---|
Description: | Pavement is a package designed to analyze spatial events occurring on roadways. It provides a comprehensive toolkit for working with spatial data, empowering users to understand patterns and trends in road-related phenomena. |
Authors: | Keisuke ANDO [aut, cre] |
Maintainer: | Keisuke ANDO <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.1 |
Built: | 2025-03-11 06:02:41 UTC |
Source: | https://github.com/NONONOexe/pavement |
The Epanechnikov function is one of the quadratic kernels used in kernel density estimation. It is defined as follows:
compute_epanechnikov(x)
compute_epanechnikov(x)
x |
A numeric vector. |
A numeric vector of weights of the kernel for each input points.
x <- seq(-3, 3, 0.1) y <- compute_epanechnikov(x) plot(x, y, xlim = c(-3, 3), ylim = c(0, 1), type = "l")
x <- seq(-3, 3, 0.1) y <- compute_epanechnikov(x) plot(x, y, xlim = c(-3, 3), ylim = c(0, 1), type = "l")
The Gaussian function is a bell-shaped function defined as follows:
compute_gaussian(x, sigma = 1)
compute_gaussian(x, sigma = 1)
x |
A numric vector. |
sigma |
The standard deviation of the Gaussian function. |
A numeric vector of weights of the kernel for each input points.
x <- seq(-3, 3, 0.1) y <- compute_gaussian(x, sigma = 1) plot(x, y, xlim = c(-3, 3), ylim = c(0, 1), type = "l")
x <- seq(-3, 3, 0.1) y <- compute_gaussian(x, sigma = 1) plot(x, y, xlim = c(-3, 3), ylim = c(0, 1), type = "l")
This function converts a bounding box to either coordinates or a polygon.
convert_bbox(bbox, output = c("coordinates", "polygon"), crs = NULL) convert_bbox_to_coordinates(bbox) convert_bbox_to_polygon(bbox, crs = NULL)
convert_bbox(bbox, output = c("coordinates", "polygon"), crs = NULL) convert_bbox_to_coordinates(bbox) convert_bbox_to_polygon(bbox, crs = NULL)
bbox |
A numeric matrix with two columns and two rows.
|
output |
A string specifying the output type. Either "coordinates" or "polygon". |
crs |
A string specifying the coordinate reference system. This is only used when converting to a polygon. |
A coordinates
object or a sfc
polygon object.
bbox <- create_bbox(center_lon = 136.9024, center_lat = 35.1649, width = 0.10, height = 0.05) convert_bbox_to_coordinates(bbox) convert_bbox_to_polygon(bbox, crs = 4326)
bbox <- create_bbox(center_lon = 136.9024, center_lat = 35.1649, width = 0.10, height = 0.05) convert_bbox_to_coordinates(bbox) convert_bbox_to_polygon(bbox, crs = 4326)
This function convolves a segmented network using a specified kernel function, typically for traffic modeling or network analysis. It computes weights densities based on the distance between links in the network and the number of events assigned to each link. Optionally, it can adjust for branching in the network.
convolute_segmented_network( segmented_network, kernel = compute_epanechnikov, bandwidth = 3, use_esd = TRUE, correct_boundary_effects = TRUE, ... )
convolute_segmented_network( segmented_network, kernel = compute_epanechnikov, bandwidth = 3, use_esd = TRUE, correct_boundary_effects = TRUE, ... )
segmented_network |
A |
kernel |
A kernel function to use for convolution (default is Epanechnikov kernel). |
bandwidth |
Numeric value representing the bandwidth for the kernel function (default is 3). |
use_esd |
If |
correct_boundary_effects |
If |
... |
Additional arguments passed to the kernel function. |
The segmented network with updated link densities.
Okabe, A., Satoh, T., & Sugihara, K. (2009). A kernel density estimation method for networks, its computational method and a GIS-based tool. International Journal of Geographical Information Science, 23(1), 7-32. doi:10.1080/13658810802475491
# Create a road network road_network <- create_road_network(sample_roads) # Assign sample accidents data road_network <- set_events(road_network, sample_accidents) # Segment the road network segmented_network <- create_segmented_network( road_network, segment_length = 0.5 ) # Check the segmented road network after assigning events segmented_network # Apply the convilution to calculate link densities using # the kernel function convoluted_network <- convolute_segmented_network(segmented_network) # Check the convoluted network with the computed densities convoluted_network # Plot the convoluted network showing the density distribution plot(convoluted_network, mode = "density")
# Create a road network road_network <- create_road_network(sample_roads) # Assign sample accidents data road_network <- set_events(road_network, sample_accidents) # Segment the road network segmented_network <- create_segmented_network( road_network, segment_length = 0.5 ) # Check the segmented road network after assigning events segmented_network # Apply the convilution to calculate link densities using # the kernel function convoluted_network <- convolute_segmented_network(segmented_network) # Check the convoluted network with the computed densities convoluted_network # Plot the convoluted network showing the density distribution plot(convoluted_network, mode = "density")
This function creates a bounding box from either cardinal coordinates (north, south, east and west) or center coordinates and dimensions (center longitude and latitude, and size of width and height).
create_bbox( north = NULL, south = NULL, east = NULL, west = NULL, center_lon = NULL, center_lat = NULL, width = NULL, height = NULL )
create_bbox( north = NULL, south = NULL, east = NULL, west = NULL, center_lon = NULL, center_lat = NULL, width = NULL, height = NULL )
north |
The northernmost latitude. |
south |
The southernmost latitude. |
east |
The easternmost longitude. |
west |
The westernmost longitude. |
center_lon |
The center longitude. |
center_lat |
The center latitude. |
width |
The width of the bounding box. |
height |
The height of the bounding box. |
A 2x2 matrix representing the bounding box.
# Create a bounding box from cardinal coordinates create_bbox( north = 35.1899, south = 35.1399, east = 136.9524, west = 136.8524 ) # Create a bounding box from center coordinates and dimensions create_bbox( center_lon = 136.9024, center_lat = 35.1649, width = 0.10, height = 0.05 )
# Create a bounding box from cardinal coordinates create_bbox( north = 35.1899, south = 35.1399, east = 136.9524, west = 136.8524 ) # Create a bounding box from center coordinates and dimensions create_bbox( center_lon = 136.9024, center_lat = 35.1649, width = 0.10, height = 0.05 )
This function creates a collection of coordinates from a sequence x and y coordinates.
create_coordinates(...)
create_coordinates(...)
... |
A sequence of x and y coordinates. |
A coordinates
object which is a matrix with x and y columns.
# Create a `coordinates` object from a sequence of x and y coordinates create_coordinates(1, 2, 3, 4) # Create a `coordinates` object from an with a vector of x and y # coordinates create_coordinates(c(1, 2, 3, 4))
# Create a `coordinates` object from a sequence of x and y coordinates create_coordinates(1, 2, 3, 4) # Create a `coordinates` object from an with a vector of x and y # coordinates create_coordinates(c(1, 2, 3, 4))
This function creates a graph object from a set of nodes and links.
create_graph(nodes, links, directed = FALSE)
create_graph(nodes, links, directed = FALSE)
nodes |
A |
links |
A |
directed |
A logical indicating whether the graph is directed. |
A igraph
object.
# Create nodes and links nodes <- extract_road_network_nodes(sample_roads) links <- extract_road_network_links(sample_roads, nodes) # Create the graph graph <- create_graph(nodes, links) graph # Plot the graph plot(graph)
# Create nodes and links nodes <- extract_road_network_nodes(sample_roads) links <- extract_road_network_links(sample_roads, nodes) # Create the graph graph <- create_graph(nodes, links) graph # Plot the graph plot(graph)
This function creates a line graph where nodes represent the midpoints of links in the input network.
create_line_graph(network)
create_line_graph(network)
network |
A |
A igraph
object representing the midpoint graph.
# Create a road network network <- create_road_network(sample_roads) # Plot the road network plot(network$graph) # Create a midpoint graph from a road network graph <- create_line_graph(network) # Plot the midpoint graph plot(graph)
# Create a road network network <- create_road_network(sample_roads) # Plot the road network plot(network$graph) # Create a midpoint graph from a road network graph <- create_line_graph(network) # Plot the midpoint graph plot(graph)
This function creates a simple feature linestring object from a series of x, y coordinates.
create_linestring(...) ## S3 method for class 'numeric' create_linestring(..., crs = NULL) ## S3 method for class 'coordinates' create_linestring(coordinates, crs = NULL, ...)
create_linestring(...) ## S3 method for class 'numeric' create_linestring(..., crs = NULL) ## S3 method for class 'coordinates' create_linestring(coordinates, crs = NULL, ...)
... |
A series of x, y coordinates. |
crs |
The coordinate reference system. |
coordinates |
A |
A simple feature linestring object.
# Create a linestring from individual coordinates linestring_1 <- create_linestring(0, 1, 1, 0, 2, 1) linestring_1 plot(linestring_1) # Create a linestring from a numeric vector linestring_2 <- create_linestring( c(0, 1, 1, 1, 1, 0, 0, 0, 0, 0.5, 1, 0.5) ) linestring_2 plot(linestring_2)
# Create a linestring from individual coordinates linestring_1 <- create_linestring(0, 1, 1, 0, 2, 1) linestring_1 plot(linestring_1) # Create a linestring from a numeric vector linestring_2 <- create_linestring( c(0, 1, 1, 1, 1, 0, 0, 0, 0, 0.5, 1, 0.5) ) linestring_2 plot(linestring_2)
This function creates a simple feature collection of points from a series of x, y coordinates.
create_points(...) ## S3 method for class 'numeric' create_points(..., crs = NULL) ## S3 method for class 'coordinates' create_points(coordinates, crs = NULL, ...)
create_points(...) ## S3 method for class 'numeric' create_points(..., crs = NULL) ## S3 method for class 'coordinates' create_points(coordinates, crs = NULL, ...)
... |
A series of x, y coordinates. |
crs |
The coordinate reference system. |
coordinates |
A |
A simple feature points object.
# Create a points from individual coordinates points_1 <- create_points(0, 1, 1, 0, 2, 1) points_1 plot(points_1) # Create a linestring from a numeric vector points_2 <- create_points( c(0, 1, 1, 1, 1, 0, 0, 0, 0, 0.5, 1, 0.5) ) points_2 plot(points_2)
# Create a points from individual coordinates points_1 <- create_points(0, 1, 1, 0, 2, 1) points_1 plot(points_1) # Create a linestring from a numeric vector points_2 <- create_points( c(0, 1, 1, 1, 1, 0, 0, 0, 0, 0.5, 1, 0.5) ) points_2 plot(points_2)
This function creates a polygon from a bounding box or a series of x, y coordinates.
create_polygon(...) ## S3 method for class 'numeric' create_polygon(..., crs = NULL) ## S3 method for class 'coordinates' create_polygon(coordinates, crs = NULL, ...)
create_polygon(...) ## S3 method for class 'numeric' create_polygon(..., crs = NULL) ## S3 method for class 'coordinates' create_polygon(coordinates, crs = NULL, ...)
... |
A series of x, y coordinates. |
crs |
The coordinate reference system. |
coordinates |
A |
A polygon object.
polygon <- create_polygon( 136.9009, 35.16377, 136.9159, 35.16377, 136.9159, 35.17377, 136.9009, 35.17377, crs = 4326 )
polygon <- create_polygon( 136.9009, 35.16377, 136.9159, 35.16377, 136.9159, 35.17377, 136.9009, 35.17377, crs = 4326 )
This function decomposes a linestring into a list of line segments, where each segment is a linestring connecting two consecutive points of the input linestring.
decompose_linestring(linestring)
decompose_linestring(linestring)
linestring |
A linestring object. |
A list of linestring objects, each representing a segment of the input linestring.
# Create a linestring object linestring <- create_linestring(0, -1, 0, 1, 2, 1, 2, 0, 0, 0) plot(linestring) # Decompose the linestring into line segments segments <- decompose_linestring(linestring) plot(segments, col = c("#E69F00", "#56B4E9", "#009E73", "#F0E442"))
# Create a linestring object linestring <- create_linestring(0, -1, 0, 1, 2, 1, 2, 0, 0, 0) plot(linestring) # Decompose the linestring into line segments segments <- decompose_linestring(linestring) plot(segments, col = c("#E69F00", "#56B4E9", "#009E73", "#F0E442"))
This function creates a data frame of durations.
create_durations(duration_length, ...)
create_durations(duration_length, ...)
duration_length |
The length of each duration. |
... |
Additional arguments passed to or from other methods. |
A durations
object.
# Create durations of 1 hour create_durations("1 hour") # Create durations of 30 minutes create_durations("30 minutes")
# Create durations of 1 hour create_durations("1 hour") # Create durations of 30 minutes create_durations("30 minutes")
This function extracts the endpoints of a set of roads. It identifies and counts the roads that intersect at each endpoint.
extract_road_endpoints(roads)
extract_road_endpoints(roads)
roads |
A linestring object representing roads. It should be have
a column named |
A points object representing road endpoints. Each endpoint has the following columns:
parent_road: A list of road IDs that intersect at the endpoint.
num_overlaps: The number of roads that intersect at the endpoint.
This function identifies and extracts intersections between roads. It considers only intersections where multiple roads on the same layer.
extract_road_intersections(roads)
extract_road_intersections(roads)
roads |
A linestring object representing roads. It should be have
a column named |
A data frame with the following columns:
parent_road: A list of road IDs that intersect at the intersection.
num_overlaps: The number of roads that intersect at the intersection.
# Extract road intersections intersections <- extract_road_intersections(sample_roads) intersections # Plot the intersections plot(sample_roads$geometry) plot(intersections$geometry, pch = 16, col = "#E69F00", add = TRUE)
# Extract road intersections intersections <- extract_road_intersections(sample_roads) intersections # Plot the intersections plot(sample_roads$geometry) plot(intersections$geometry, pch = 16, col = "#E69F00", add = TRUE)
This function extracts the road network links from a set of road geometries. It splits the road geometries at the nodes and creates a new sf object representing the road network links.
extract_road_network_links(roads, nodes)
extract_road_network_links(roads, nodes)
roads |
A linestring object representing the roads. |
nodes |
A point object representing the road network nodes. |
A linestring object representing the road network links.
To create the nodes, use the extract_road_network_nodes()
This function extracts nodes from roads represented as linestring objects downloaded from OpenStreetMap. Nodes are defined as intersections between roads and endpoints of road segments.
extract_road_network_nodes(roads)
extract_road_network_nodes(roads)
roads |
A linestring object representing roads. |
A points object representing road network nodes.
This function extracts the segmented network links from a road network based on a specified set of segmented network nodes. It splits the linestrings of the road network links at the points of the segmented network nodes to create the segmented network links.
extract_segmented_network_links( road_network, segmented_network_nodes, tolerance = 1e-05 )
extract_segmented_network_links( road_network, segmented_network_nodes, tolerance = 1e-05 )
road_network |
A |
segmented_network_nodes |
A data frame representing the segmented network nodes. |
tolerance |
A numeric value representing the maximum distance allowed between a linestring of a road link and a point of a segmented network node. If the distance exceeds this value, the point will not be used to split the linestring. |
A data frame representing the segmented network links.
# Create a road network road_network <- create_road_network(sample_roads) # Extract segmented network nodes by length of 1 segmented_network_nodes <- extract_segmented_network_nodes(road_network, 1) # Extract segmented network links segmented_network_links <- extract_segmented_network_links( road_network, segmented_network_nodes ) segmented_network_links # Plot the segmented network nodes and links plot(segmented_network_links$geometry, col = "#E69F00") plot(segmented_network_nodes$geometry, pch = 16, add = TRUE)
# Create a road network road_network <- create_road_network(sample_roads) # Extract segmented network nodes by length of 1 segmented_network_nodes <- extract_segmented_network_nodes(road_network, 1) # Extract segmented network links segmented_network_links <- extract_segmented_network_links( road_network, segmented_network_nodes ) segmented_network_links # Plot the segmented network nodes and links plot(segmented_network_links$geometry, col = "#E69F00") plot(segmented_network_nodes$geometry, pch = 16, add = TRUE)
This function extracts nodes at regular intervals along each link in a road network
extract_segmented_network_nodes(road_network, segment_length)
extract_segmented_network_nodes(road_network, segment_length)
road_network |
A |
segment_length |
The length of each segment to sample along the links. |
An sf
object with the sampled points.
# Create a road network road_network <- create_road_network(sample_roads) # Extract nodes with a segment length of 1 segmented_network_nodes <- extract_segmented_network_nodes(road_network, 1) segmented_network_nodes # Plot the segmented network nodes plot(road_network) plot(segmented_network_nodes$geometry, add = TRUE, pch = 16, col = "#E69F00")
# Create a road network road_network <- create_road_network(sample_roads) # Extract nodes with a segment length of 1 segmented_network_nodes <- extract_segmented_network_nodes(road_network, 1) segmented_network_nodes # Plot the segmented network nodes plot(road_network) plot(segmented_network_nodes$geometry, add = TRUE, pch = 16, col = "#E69F00")
fetch_roads()
fetches road data from OpenStreetMap. It retrieves roads
within a specified bounding box or within an area defined by a center point
and a radius. Additionally, roads can be cropped to fit within the specified
boundaries.
fetch_roads(x, ...) ## S3 method for class 'matrix' fetch_roads(x, crop = FALSE, ...) ## S3 method for class 'sfc_POINT' fetch_roads(x, radius = 15, crop = FALSE, circle_crop = FALSE, ...) ## S3 method for class 'POINT' fetch_roads(x, radius = 15, crop = FALSE, circle_crop = FALSE, ...) ## S3 method for class 'numeric' fetch_roads(x, y, radius = 15, crop = FALSE, circle_crop = FALSE, ...) ## S3 method for class 'character' fetch_roads(x, crop = FALSE, circle_crop = FALSE, ...)
fetch_roads(x, ...) ## S3 method for class 'matrix' fetch_roads(x, crop = FALSE, ...) ## S3 method for class 'sfc_POINT' fetch_roads(x, radius = 15, crop = FALSE, circle_crop = FALSE, ...) ## S3 method for class 'POINT' fetch_roads(x, radius = 15, crop = FALSE, circle_crop = FALSE, ...) ## S3 method for class 'numeric' fetch_roads(x, y, radius = 15, crop = FALSE, circle_crop = FALSE, ...) ## S3 method for class 'character' fetch_roads(x, crop = FALSE, circle_crop = FALSE, ...)
x |
An object defining the area or location of interest. This can be:
|
... |
Additional arguments passed to the method. |
crop |
A logical value indicating whether to crop road data to the
specified area (default: |
radius |
Numeric value representing the search radius in meters
(default: |
circle_crop |
A logical value indicating whether to crop roads within a
circular area instead of a bounding box (default: |
y |
Numeric value representing latitude (required if |
An sf
object of class LINESTRING
, containing road data with
the followings columns:
Unique road identifier
Road classification (e.g. "residential", "primary")
Road name
Layer information for roads at different elevations
Logical indicating whether the road is one-way
OpenStreetMap unique identifier
## Not run: # Download road data bbox <- create_bbox( north = 35.17377, south = 35.16377, east = 136.91590, west = 136.90090 ) roads <- fetch_roads(bbox) # Plot the roads plot(roads$geometry) ## End(Not run)
## Not run: # Download road data bbox <- create_bbox( north = 35.17377, south = 35.16377, east = 136.91590, west = 136.90090 ) roads <- fetch_roads(bbox) # Plot the roads plot(roads$geometry) ## End(Not run)
This function filters a given geometries by specific type and casts it to the specified type.
filter_and_cast_geometries( geometries, geometry_type = c("POINT", "LINESTRING", "POLYGON") ) get_points(geometries) get_linestrings(geometries) get_polygons(geometries)
filter_and_cast_geometries( geometries, geometry_type = c("POINT", "LINESTRING", "POLYGON") ) get_points(geometries) get_linestrings(geometries) get_polygons(geometries)
geometries |
A |
geometry_type |
The type of geometry to filter and cast to. Must be one of "POINT", "LINESTRING", or "POLYGON". |
A sf
object containing only the specified type of geometry.
plot(1, type = "n", xlab = "", ylab = "", axes = FALSE, xlim = c(0, 12), ylim = c(0, 10)) text(0, c(2, 6), c("Single", "Multiple"), srt = 90, cex = 1) text(c(2, 6, 10), 8, c("Point", "Linestring", "Polygon"), cex = 1) geometries <- sf::st_sf(geometry = c( # POINT create_points(2, 2), # LINESTRING create_linestring(5, 1, 7, 3), # POLYGON create_polygon(9, 1, 9, 3, 11, 3, 11, 1), # MULTIPOINT sf::st_union(create_points(1, 7, 2, 6, 3, 5)), # MULTILINESTRING sf::st_union( create_linestring(5, 6, 6, 7), create_linestring(6, 5, 7, 6) ), # MULTIPOLYGON sf::st_union( create_polygon(9, 7, 10, 7, 10, 6, 9, 6), create_polygon(10, 5, 11, 6, 11, 5) ) )) plot(geometries, pch = 16, lwd = 2, add = TRUE) # Get points from geometries plot(get_points(geometries), pch = 16) # Get linestrings from geometries plot(get_linestrings(geometries), lwd = 2) # Get polygons from geometries plot(get_polygons(geometries), lwd = 2)
plot(1, type = "n", xlab = "", ylab = "", axes = FALSE, xlim = c(0, 12), ylim = c(0, 10)) text(0, c(2, 6), c("Single", "Multiple"), srt = 90, cex = 1) text(c(2, 6, 10), 8, c("Point", "Linestring", "Polygon"), cex = 1) geometries <- sf::st_sf(geometry = c( # POINT create_points(2, 2), # LINESTRING create_linestring(5, 1, 7, 3), # POLYGON create_polygon(9, 1, 9, 3, 11, 3, 11, 1), # MULTIPOINT sf::st_union(create_points(1, 7, 2, 6, 3, 5)), # MULTILINESTRING sf::st_union( create_linestring(5, 6, 6, 7), create_linestring(6, 5, 7, 6) ), # MULTIPOLYGON sf::st_union( create_polygon(9, 7, 10, 7, 10, 6, 9, 6), create_polygon(10, 5, 11, 6, 11, 5) ) )) plot(geometries, pch = 16, lwd = 2, add = TRUE) # Get points from geometries plot(get_points(geometries), pch = 16) # Get linestrings from geometries plot(get_linestrings(geometries), lwd = 2) # Get polygons from geometries plot(get_polygons(geometries), lwd = 2)
This function filters points that are within a specified tolerance distance from a reference linestring.
filter_points_within_tolerance(points, linestring, tolerance = 0.01)
filter_points_within_tolerance(points, linestring, tolerance = 0.01)
points |
A |
linestring |
A linestring object. |
tolerance |
A numeric value representing the maximum allowable distance between points and the linestring. Points within this distance from the linestring will be included in the filtered set. |
A sfc
object containing the filtered points.
# Create a points points <- create_points( 0.000, 1.000, 0.500, 0.600, 1.000, 0.010, 1.500, 0.501, 2.000, 0.990 ) # Create a linestring linestring <- create_linestring(0, 1, 1, 0, 2, 1) # Plot the points plot(linestring, col = "gray") plot(points, add = TRUE) # Filter points within a tolerance distance (default: 0.01) filtered_points <- filter_points_within_tolerance(points, linestring) # Plot the filtered points plot(linestring, col = "gray") plot(filtered_points, add = TRUE)
# Create a points points <- create_points( 0.000, 1.000, 0.500, 0.600, 1.000, 0.010, 1.500, 0.501, 2.000, 0.990 ) # Create a linestring linestring <- create_linestring(0, 1, 1, 0, 2, 1) # Plot the points plot(linestring, col = "gray") plot(points, add = TRUE) # Filter points within a tolerance distance (default: 0.01) filtered_points <- filter_points_within_tolerance(points, linestring) # Plot the filtered points plot(linestring, col = "gray") plot(filtered_points, add = TRUE)
This function find the index of the duration that contains the event time.
find_duration(events, durations, ...)
find_duration(events, durations, ...)
events |
A spatiotemporal event object. |
durations |
A duration object. |
... |
Additional arguments passed to or from other methods. |
A vector of indices corresponding to the durations that contain the event times.
# Create a spatiotemporal event object accidents <- create_spatiotemporal_events(sample_accidents) # Create a duration object durations <- create_durations("1 hour") # Find the duration that contains each accident find_duration(accidents, durations)
# Create a spatiotemporal event object accidents <- create_spatiotemporal_events(sample_accidents) # Create a duration object durations <- create_durations("1 hour") # Find the duration that contains each accident find_duration(accidents, durations)
This function generates unique IDs based on parent IDs. It first extracts the first ID from each parent ID, then ranks these IDs and uses the ranks to format the IDs.
generate_ids(parent_list, id_format)
generate_ids(parent_list, id_format)
parent_list |
A list of parent IDs. |
id_format |
A format string for the IDs. |
A vector of unique IDs.
parent_list <- c("rd_0001", "rd_0002", "rd_0003") id_format <- "jn_%06x" generate_ids(parent_list, id_format)
parent_list <- c("rd_0001", "rd_0002", "rd_0003") id_format <- "jn_%06x" generate_ids(parent_list, id_format)
This function retrieves all links connected to a specified node in a road network.
get_connected_links(network, node_ids)
get_connected_links(network, node_ids)
network |
A |
node_ids |
A vector of node IDs to find connected links for. |
A vector of link IDs connected to the specified node.
# Create a road network road_network <- create_road_network(sample_roads) target_node <- road_network$nodes[3,]$id target_node # Get connected links connected_links <- get_connected_links(road_network, target_node) connected_links # Plot the target node and the connected links is_connected <- road_network$links$id %in% connected_links connected_links_geom <- road_network$links$geometry[is_connected] plot(road_network, col = "gray") plot(connected_links_geom, add = TRUE, col = "#E69F00", lwd = 2) plot(road_network$nodes[3,]$geometry, add = TRUE, pch = 19)
# Create a road network road_network <- create_road_network(sample_roads) target_node <- road_network$nodes[3,]$id target_node # Get connected links connected_links <- get_connected_links(road_network, target_node) connected_links # Plot the target node and the connected links is_connected <- road_network$links$id %in% connected_links connected_links_geom <- road_network$links$geometry[is_connected] plot(road_network, col = "gray") plot(connected_links_geom, add = TRUE, col = "#E69F00", lwd = 2) plot(road_network$nodes[3,]$geometry, add = TRUE, pch = 19)
A dataset representing reference points for Japan Geodetic Datum 2011 (JDG2011). This dataset contains system numbers, longitude, latitude, and corresponding coordinate reference system (CRS) codes for various geodetic reference points in Japan.
jdg2011_datum
jdg2011_datum
A data.frame
with 19 rows and 4 columns:
System number (Roman numeral I-XIX) representing geodetic reference zones
Longitude in decimal degrees
Latitude in decimal degrees
Coordinate reference system (CRS) code for reference point
# Show the dataset jdg2011_datum
# Show the dataset jdg2011_datum
osm_highway_values
contains a character vector of values for the 'highway'
tag in OpenStreetMap data.
osm_highway_values
osm_highway_values
A character vector of length 12.
osm_highway_values
osm_highway_values
This function plots a road network.
## S3 method for class 'road_network' plot(x, y, mode = c("default", "event", "graph"), ...)
## S3 method for class 'road_network' plot(x, y, mode = c("default", "event", "graph"), ...)
x |
A road network object. |
y |
This argument is not used. |
mode |
The plotting mode. "event" mode shows the location events
assigned to the road network. "graph" mode shows the direction of links
when the network is directed. This utilizes the |
... |
Additional arguments passed to or from other methods. |
# Create the road network road_network <- create_road_network(sample_roads, events = sample_accidents) # Plot the road network plot(road_network) # Plot the road network with events plot(road_network, mode = "event") # Plot the road network as a graph plot(road_network, mode = "graph")
# Create the road network road_network <- create_road_network(sample_roads, events = sample_accidents) # Plot the road network plot(road_network) # Plot the road network with events plot(road_network, mode = "event") # Plot the road network as a graph plot(road_network, mode = "graph")
This function removes points from a set of points that are within a specified tolerance distance of the start or end point of a linestring.
remove_points_near_endpoints(points, linestring, tolerance = 0.01)
remove_points_near_endpoints(points, linestring, tolerance = 0.01)
points |
A |
linestring |
A linestring object. |
tolerance |
A numeric value representing the maximum distance from the line's ends to consider points for filtering. Points within this distance will be excluded. |
A sfc
object containing the filtered points.
# Create a points points <- create_points( 0.000, 1.000, 0.500, 0.600, 1.000, 0.010, 1.500, 0.501, 2.000, 0.990 ) # Create a linestring linestring <- create_linestring(0, 1, 1, 0, 2, 1) # Plot the points plot(linestring, col = "gray") plot(points, add = TRUE) # Filter points within a tolerance distance (default: 0.01) filtered_points <- remove_points_near_endpoints(points, linestring) # Plot the filtered points plot(linestring, col = "gray") plot(filtered_points, add = TRUE)
# Create a points points <- create_points( 0.000, 1.000, 0.500, 0.600, 1.000, 0.010, 1.500, 0.501, 2.000, 0.990 ) # Create a linestring linestring <- create_linestring(0, 1, 1, 0, 2, 1) # Plot the points plot(linestring, col = "gray") plot(points, add = TRUE) # Filter points within a tolerance distance (default: 0.01) filtered_points <- remove_points_near_endpoints(points, linestring) # Plot the filtered points plot(linestring, col = "gray") plot(filtered_points, add = TRUE)
This function constructs a road network from a set of roads. The road network is represented nodes and links between nodes. Nodes are defined as intersections between roads and endpoints of road segments.
create_road_network(roads, directed = FALSE, events = NULL, ...)
create_road_network(roads, directed = FALSE, events = NULL, ...)
roads |
A linestring object representing roads. |
directed |
Logical indicating whether the road network is directed. |
events |
A |
... |
Additional arguments passed to or from other methods. |
A road network object.
# Create the road network road_network <- create_road_network(sample_roads) # Print the road network summary road_network # Plot the road network plot(road_network)
# Create the road network road_network <- create_road_network(sample_roads) # Print the road network summary road_network # Plot the road network plot(road_network)
A sample dataset containing information about 10 accidents. The dataset is for demonstration and testing and does not represent real-world events.
sample_accidents
sample_accidents
A sf
object with 10 rows and 4 columns:
Accident ID
Time of the accident (in hours)
Weather condition at the time of the accident
Severity of the accident
Point geometry of the accident location
# Show information about the accidents sample_accidents # Plot the locations of the accidents plot(sample_roads$geometry) plot(sample_accidents$geometry, pch = 4, col = "red", add = TRUE)
# Show information about the accidents sample_accidents # Plot the locations of the accidents plot(sample_roads$geometry) plot(sample_accidents$geometry, pch = 4, col = "red", add = TRUE)
This function samples points at regular intervals along a linestring object.
sample_points_along_linestring(linestrings, segment_length)
sample_points_along_linestring(linestrings, segment_length)
linestrings |
A |
segment_length |
The desired length of each segment between sampled points. |
A sfc
object containing the sampled points.
library(sf) # Create a linestrings linestrings <- c( create_linestring(0, 1, 2, 1), create_linestring(1, 1.3, 1, 0, 2, 0.5) ) # Sample points along the linestrings sampled_points <- sample_points_along_linestring(linestrings, 0.5) # Plot the sampled points plot(linestrings) plot(sampled_points, add = TRUE, pch = 16, col = c("#E69F00", "#56B4E9"))
library(sf) # Create a linestrings linestrings <- c( create_linestring(0, 1, 2, 1), create_linestring(1, 1.3, 1, 0, 2, 0.5) ) # Sample points along the linestrings sampled_points <- sample_points_along_linestring(linestrings, 0.5) # Plot the sampled points plot(linestrings) plot(sampled_points, add = TRUE, pch = 16, col = c("#E69F00", "#56B4E9"))
A sample dataset representing simple roads. It intended for demonstration and testing and does not represent real-world roads.
sample_roads
sample_roads
A sf
linestring object with 6 rows and 2 columns:
Road ID
Layer of the road (indicates a road on an elevated structure such as a bridge, tunnel, or highway)
Linestring geometry of the road
# Show information about the roads sample_roads # Shape of the roads plot(sample_roads$geometry)
# Show information about the roads sample_roads # Shape of the roads plot(sample_roads$geometry)
This function creates a segmented road network by dividing each link of the input road network into segments of a specified length.
create_segmented_network(road_network, segment_length = 1, events = NULL, ...) ## S3 method for class 'road_network' create_segmented_network(road_network, segment_length = 1, events = NULL, ...)
create_segmented_network(road_network, segment_length = 1, events = NULL, ...) ## S3 method for class 'road_network' create_segmented_network(road_network, segment_length = 1, events = NULL, ...)
road_network |
A |
segment_length |
A numeric value specifying the length of each segment. |
events |
A |
... |
Additional arguments passed to or from other methods. |
A segmented_network
object.
# Create a road network road_network <- create_road_network(sample_roads) # Create a segmented road network segmented_network <- create_segmented_network( road_network, segment_length = 0.5 ) segmented_network # Plot the segmented road network plot(segmented_network)
# Create a road network road_network <- create_road_network(sample_roads) # Create a segmented road network segmented_network <- create_segmented_network( road_network, segment_length = 0.5 ) segmented_network # Plot the segmented road network plot(segmented_network)
This function sets events on a space.
set_events(x, events, ...)
set_events(x, events, ...)
x |
A space object. |
events |
A sf or spatiotemporal events object. |
... |
Additional arguments passed to or from other methods. |
The input object with the events added.
# Create the road network road_network <- create_road_network(sample_roads) # Set accidents on the road network road_network <- set_events(road_network, sample_accidents)
# Create the road network road_network <- create_road_network(sample_roads) # Set accidents on the road network road_network <- set_events(road_network, sample_accidents)
This function creates a spatiotemporal event collection object from
a given sf
object, allowing spatial and temporal data to be
handled together.
create_spatiotemporal_events(x, ...) ## S3 method for class 'sf' create_spatiotemporal_events( x, time_column_name = "time", time_format = "%H", ... )
create_spatiotemporal_events(x, ...) ## S3 method for class 'sf' create_spatiotemporal_events( x, time_column_name = "time", time_format = "%H", ... )
x |
A |
... |
Additional arguments passed to or from other methods. |
time_column_name |
A character string specifying the column name
in |
time_format |
A character string specifying the format of
the time data in the |
An sf
object with class spatiotemporal_events
added,
representing a spatiotemporal event collection.
# Simple feature collection object representing accidents sample_accidents # Create a spatiotemporal event collection create_spatiotemporal_events(sample_accidents)
# Simple feature collection object representing accidents sample_accidents # Create a spatiotemporal event collection create_spatiotemporal_events(sample_accidents)
This function creates a spatiotemporal network from a road network.
create_spatiotemporal_network( road_network, spatial_length = 1, temporal_length = "1 hour", events = NULL, ... )
create_spatiotemporal_network( road_network, spatial_length = 1, temporal_length = "1 hour", events = NULL, ... )
road_network |
A |
spatial_length |
The spatial length of segment. |
temporal_length |
The temporal length of segment. |
events |
A event collection object. |
... |
Additional arguments passed to or from other methods. |
A spatiotemporal_network
object.
# Create a road network road_network <- create_road_network(sample_roads) # Create a spatiotemporal road network spatiotemporal_network <- create_spatiotemporal_network( road_network, spatial_length = 0.5, temporal_length = "4 hour" ) spatiotemporal_network # Plot the spatiotemporal road network plot(spatiotemporal_network)
# Create a road network road_network <- create_road_network(sample_roads) # Create a spatiotemporal road network spatiotemporal_network <- create_spatiotemporal_network( road_network, spatial_length = 0.5, temporal_length = "4 hour" ) spatiotemporal_network # Plot the spatiotemporal road network plot(spatiotemporal_network)
Split a linestring into multiple segments
split_linestring(linestring, split_points, tolerance = 0.01)
split_linestring(linestring, split_points, tolerance = 0.01)
linestring |
A linestring object. |
split_points |
A |
tolerance |
A numeric value representing the maximum distance allowed between the linestring and the split points. If the distance between a split point and the linestring exceeds this value, the point will not be used to split the linestring. |
A sfc
object containing the split linestrings.
# Create a linestring linestring <- create_linestring(0, -1, 0, 1, 2, 1, 2, 0, 0, 0) # Create a set of split points split_points <- create_points(0, 0, 1, 1, 2, 0) # Plot the linestring and split points plot(linestring) plot(split_points, add = TRUE) # Split the linestring segments <- split_linestring(linestring, split_points) # Plot the split linestrings plot(segments, col = c("#E69F00", "#56B4E9", "#009E73", "#F0E442"), lwd = 2)
# Create a linestring linestring <- create_linestring(0, -1, 0, 1, 2, 1, 2, 0, 0, 0) # Create a set of split points split_points <- create_points(0, 0, 1, 1, 2, 0) # Plot the linestring and split points plot(linestring) plot(split_points, add = TRUE) # Split the linestring segments <- split_linestring(linestring, split_points) # Plot the split linestrings plot(segments, col = c("#E69F00", "#56B4E9", "#009E73", "#F0E442"), lwd = 2)
This function transforms a spatial object to Cartesian coordinates (plane rectangular coordinate system) or geographic coordinates (WGS84; EPSG:4326). The Cartesian system currently supports only Aichi Prefecture's JDG2011 system (EPSG:6675).
transform_coordinates( spatial_object, target = c("cartesian", "geographic"), quiet = FALSE ) transform_to_cartesian(spatial_object, quiet = FALSE) transform_to_geographic(spatial_object, quiet = FALSE)
transform_coordinates( spatial_object, target = c("cartesian", "geographic"), quiet = FALSE ) transform_to_cartesian(spatial_object, quiet = FALSE) transform_to_geographic(spatial_object, quiet = FALSE)
spatial_object |
A spatial object. |
target |
A character string specifying the target coordinate system:
|
quiet |
Logical. If |
If the CRS is missing (NA), a warning is issued, and the original object is
returned. The warning can be suppressed with the quiet
argument.
A spatial object transformed to the specified coordinate system.
# Create points points <- create_points(136.9024, 35.1649, crs = 4326) points # Transform to Cartesian coordinates transformed <- transform_to_cartesian(points) transformed # Transform to geographic coordinates transformed <- transform_to_geographic(points) transformed
# Create points points <- create_points(136.9024, 35.1649, crs = 4326) points # Transform to Cartesian coordinates transformed <- transform_to_cartesian(points) transformed # Transform to geographic coordinates transformed <- transform_to_geographic(points) transformed