Thank you! I have been following this guide so far and its been really helpful. However, my issue is: where the speed is calculated as a separate column titled 's', the units are in m/s. Though this is useful, it seems that the conversion to this unit is incorrect, as it has mistaken the distances between the points to be in imperial yards instead of metric meters. I believe it is this section of code which must be edited to have the correct conversion ratio. Please see below:
points2line_trajectory = function(p) {
c = st_coordinates(p)
i = seq(nrow(p) - 2)
l = purrr::map(i, ~ sf::st_linestring(c[.x:(.x + 1), ]))
s = purrr::map_dbl(i, function(x) {
geosphere::distHaversine(c[x, ], c[(x + 1), ]) /
as.numeric(p$time[x + 1] - p$time[x])
}
)
lfc = sf::st_sfc(l)
a = seq(length(lfc)) + 1 # sequence to subset
p_data = cbind(sf::st_set_geometry(p[a, ], NULL), s)
sf::st_sf(p_data, geometry = lfc)
}
l = points2line_trajectory(p)
plot(l)
@jlacko mentioned about changing
geosphere::distHaversine
To
sf::st_distance
However, when I run this section of code with the replacement recommended, this error occurs:
> l = points2line_trajectory(p)
Error in UseMethod("st_geometry") :
no applicable method for 'st_geometry' applied to an object of class "c('double', 'numeric')"
In addition: Warning messages:
1: In if (is.na(x)) NA_crs_ else if (inherits(x, "crs")) x else if (is.character(x)) { :
the condition has length > 1 and only the first element will be used
2: In CPL_crs_from_input(x) :
GDAL Error 1: PROJ: proj_create_from_database: crs not found
3: In if (is.na(x)) NA_crs_ else if (inherits(x, "crs")) x else if (is.character(x)) { :
the condition has length > 1 and only the first element will be used
4: In CPL_crs_from_input(x) :
Error in UseMethod("st_geometry") :
no applicable method for 'st_geometry' applied to an object of class "c('double', 'numeric')"
How can I resolve this?
Once the conversion is correct, as I stated in my original query, I then want to select the GPS co-ordinates that have speeds above the set threshold and calculate the distance covered between these. Do you know how I would be able to do that?
I don't have a great deal of experience in RStudio so please excuse any silly questions/queries I might have asked. Thank you in advance - I really appreciate any help you can provide as this is something I'm really struggling with. I just wish there was a counselling/calling service for help with RStudio as I worry I don't explain my issues very clearly in text.