Closed wangzhao0217 closed 10 months ago
Hi @Robinlovelace Currently, I couldn't find a more efficient method to prevent sideroads from getting values from the main road, except to use the angle calculation method. I did the following update on file rnet_join.R
updating
for(i in sum_cols) {
# TODO: deduplicate
length_y = as.numeric(sf::st_length(rnet_y))
mask <- (res_sf$angle < 15) | (res_sf$angle > 160)
# i = sum_cols[1]
res_sf[mask, i] <- res_sf[mask, i] / res_sf[mask, "length_x"]
over_estimate <- sum(res_sf[mask, i] * res_sf[mask, "length_x"], na.rm = TRUE) /
sum(rnet_y[mask, i] * length_y, na.rm = TRUE)
res_sf[mask, i] <- res_sf[mask, i] / over_estimate
}
get_vector <- function(line) {
if (class(line) == "LINESTRING") {
coords <- st_coordinates(line)
start <- coords[1, 1:2]
end <- coords[2, 1:2]
} else { # For MultiLineStrings, just use the first line
first_line <- st_cast(line, "LINESTRING")[[1]]
coords <- st_coordinates(first_line)
start <- coords[1, 1:2]
end <- coords[2, 1:2]
}
return(c(end[1] - start[1], end[2] - start[2]))
}
calculate_angle <- function(vector1, vector2) { dot_product <- sum(vector1 vector2) magnitude_product <- sqrt(sum(vector1^2)) sqrt(sum(vector2^2)) cos_angle <- dot_product / magnitude_product angle <- acos(cos_angle) * (180 / pi) return(angle) }
However, it is still not working, will keep fixing it.
Thanks Zhao, will take a look.
will make new pr
Sounds good, looking forward to reviewing it and seeing the results.