ropensci / stplanr

Sustainable transport planning with R
https://docs.ropensci.org/stplanr
Other
416 stars 66 forks source link

Comparing the results between angle_diff with calculate_angle/get_vector #528

Closed wangzhao0217 closed 10 months ago

wangzhao0217 commented 10 months ago

Hi @Robinlovelace, I am reviewing the results obtained from angle_diff function and from calculate_angle/get_vector.

    rnetj$angle = sapply(1:nrow(rnetj), function(i) {
    calculate_angle(get_vector(rnetj$corr_line_geometry_buffer[[i]]), get_vector(rnetj$corr_line_geometry_point[[i]]))
    })
    rnetj$angle_2 = sapply(1:nrow(rnetj), function(i) {
      # Check if either of the geometries is empty
      if (st_is_empty(rnetj$corr_line_geometry_buffer[i]) || 
          st_is_empty(rnetj$corr_line_geometry_point[i])) {
        return(NA)
      }

      # Extract the two lines into a temporary 'sf' object
      temp_sf <- rbind(
        data.frame(geometry = rnetj$corr_line_geometry_buffer[i]), 
        data.frame(geometry = rnetj$corr_line_geometry_point[i])
      )
      temp_sf <- st_as_sf(temp_sf)

      # Get the angles difference using the temporary 'sf' object
      angles = angle_diff(temp_sf, angle = 0)

      # Return the absolute difference between the two angles
      abs(angles[1] - angles[2])
    })

There are some noticeable inconsistencies causing the problem. For example : image image image image image image Would you like me to investigate and identify the issue? or use calculate_angle/get_vector to test on 3km dataset?

Robinlovelace commented 10 months ago

Hi Zhao, yes we should diagnose the issue. I suggest creating a minimal reproducible example to explore.