diff --git a/NAMESPACE b/NAMESPACE index 0de2979..d3d63c7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,7 +20,6 @@ S3method(split_linestring,LINESTRING) S3method(split_linestring,sfc_LINESTRING) S3method(summary,road_network) S3method(summary,segmented_network) -export(assign_event_to_link) export(compute_epanechnikov) export(compute_gaussian) export(convolute_segmented_network) diff --git a/R/assign-event-to-link.R b/R/assign-event-to-link.R deleted file mode 100644 index 9c5e584..0000000 --- a/R/assign-event-to-link.R +++ /dev/null @@ -1,38 +0,0 @@ -#' Assign events to the nearest link -#' -#' This function assigns events to the nearest link in a segmented road -#' network. -#' -#' @param segmented_network A `segmented_network` object, which contains -#' a list of segmented links and nodes, representing the segmented road -#' network. -#' @param events A `sf` object representing events, such as traffic accidents, -#' with location information. -#' @return A `segmented_network` object with events assigned to links. Each -#' link will have a `count` attribute indicating the number of events -#' assigned to it. -#' @export -#' @examples -#' # Create the segmented road network -#' road_network <- create_road_network(sample_roads) -#' segmented_network <- create_segmented_network(road_network) -#' -#' # Assign accidents to the nearest link -#' segmented_network <- assign_event_to_link( -#' segmented_network, -#' sample_accidents -#' ) -#' -#' # Plot the segmented road network with events -#' plot(segmented_network, mode = "event") -assign_event_to_link <- function(segmented_network, events) { - # Add events to `segment_network` object - segmented_network$events <- events - - # Assign the event counts to the corresponding links - event_counts <- table(st_nearest_feature(events, segmented_network$links)) - link_indices <- as.integer(names(event_counts)) - segmented_network$links$count[link_indices] <- event_counts - - return(segmented_network) -} diff --git a/R/convolute-segmented-network.R b/R/convolute-segmented-network.R index 51c0c95..727fa48 100644 --- a/R/convolute-segmented-network.R +++ b/R/convolute-segmented-network.R @@ -26,18 +26,15 @@ #' # 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 #' ) #' -#' # Assign sample accidents data to the links of the segmented road network -#' segmented_network <- assign_event_to_link( -#' segmented_network, -#' sample_accidents -#' ) -#' #' # Check the segmented road network after assigning events #' segmented_network #' diff --git a/man/assign_event_to_link.Rd b/man/assign_event_to_link.Rd deleted file mode 100644 index 4b66746..0000000 --- a/man/assign_event_to_link.Rd +++ /dev/null @@ -1,39 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/assign-event-to-link.R -\name{assign_event_to_link} -\alias{assign_event_to_link} -\title{Assign events to the nearest link} -\usage{ -assign_event_to_link(segmented_network, events) -} -\arguments{ -\item{segmented_network}{A \code{segmented_network} object, which contains -a list of segmented links and nodes, representing the segmented road -network.} - -\item{events}{A \code{sf} object representing events, such as traffic accidents, -with location information.} -} -\value{ -A \code{segmented_network} object with events assigned to links. Each -link will have a \code{count} attribute indicating the number of events -assigned to it. -} -\description{ -This function assigns events to the nearest link in a segmented road -network. -} -\examples{ -# Create the segmented road network -road_network <- create_road_network(sample_roads) -segmented_network <- create_segmented_network(road_network) - -# Assign accidents to the nearest link -segmented_network <- assign_event_to_link( - segmented_network, - sample_accidents -) - -# Plot the segmented road network with events -plot(segmented_network, mode = "event") -} diff --git a/man/convolute_segmented_network.Rd b/man/convolute_segmented_network.Rd index f75131c..952000c 100644 --- a/man/convolute_segmented_network.Rd +++ b/man/convolute_segmented_network.Rd @@ -41,18 +41,15 @@ branching in the network. # 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 ) -# Assign sample accidents data to the links of the segmented road network -segmented_network <- assign_event_to_link( - segmented_network, - sample_accidents -) - # Check the segmented road network after assigning events segmented_network diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 5dc1034..5ef649b 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -75,7 +75,7 @@ reference: with high event frequency with these functions. contents: - spatiotemporal_event - - assign_event_to_link + - set_events - convolute_segmented_network - starts_with("compute_") - create_line_graph