Created
December 1, 2022 08:40
-
-
Save simbamangu/1e6da21ef197a30ad5870ca8ec2dca47 to your computer and use it in GitHub Desktop.
Read a directory of GPX files and summarise by data type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read a directory of GPX files and summarise by data type | |
require(sf) | |
require(dplyr) | |
# Read all the GPX filenames/locations in target, recursive | |
gpxs <- | |
dir( | |
path = "../_data/tracklogs/", | |
recursive = T, | |
full.names = T, | |
pattern = "*.gpx" | |
) | |
# Create an empty tibble | |
gpx_count <- length(gpxs) | |
gpxs_summary <- tibble( | |
sourcefile = character(gpx_count), | |
waypoints = numeric(gpx_count), | |
routes = numeric(gpx_count), | |
tracks = numeric(gpx_count), | |
route_points = numeric(gpx_count), | |
track_points = numeric(gpx_count) | |
) | |
# Update each row with filename and number of features | |
for (n in 1:gpx_count) { | |
gpxs_summary[n, 1] <- basename(gpxs[n]) | |
gpxs_summary[n, 2:6] <- as.list(st_layers(gpxs[n])$features) | |
} | |
# Save it with YYYYMMDDTHHMMSS stamp | |
write_csv(gpxs_summary, file = paste0( | |
"GPXfiles_summary_", | |
format(Sys.time(), '%Y%m%dT%H%M%S'), | |
".csv" | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment