Last active
August 17, 2022 23:53
-
-
Save mdmadhu/e92ee7a2fc595b3941c596c35662f1a8 to your computer and use it in GitHub Desktop.
R Script to pull together GPS waypoints from multiple GPX files into a single CSV file
This file contains hidden or 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
# MD Madhusudan, [email protected], Nature Conservation Foundation, 2016-04-10 | |
# Code to import waypoints from multiple GPX files in a folder, | |
# extract coordinates from each file into a single object, and | |
# export to CSV or some other format | |
# | |
# - initialisation steps | |
library(plotKML) | |
library(dplyr) | |
# Set working directory to folder where all the GPX Waypoint files are present | |
setwd("~/Desktop/") | |
# - List all filenames in folder starting with "Waypoint" | |
# Works for waypoint files with names like "Waypoints_22-FEB-16.gpx" | |
files <- list.files(pattern = "\\bWaypoints_") | |
# Initialise empty data frame | |
wpfull <- NULL | |
for (i in 1:length(files)) { | |
# - Select first file from the list and import data into R object | |
wplist <- readGPX(files[i], way=T) | |
# extract latitude, longituDe, elevation, time, name and comments and apppend to R dataframe | |
wpdf<- wplist$waypoints | |
# append dataframe from last index to a full waypoint object | |
wpfull <- bind_rows(wpfull, wpdf) | |
} | |
# export object with all waypoints to csv file | |
write.csv(wpfull, "finalwp.csv") | |
Updated script with sf utilities incorporated here:
https://github.com/vjjan91/acoustics-westernGhats/blob/master/code/04_extract-waypoints-from-gps.R
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The dataframe containing the consecutive points of your trackline is nested within the wplist as a list in a list in a list. I was able to access mine using the following:
tracklinedf <- wplist$tracks[[1]][[1]]