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") | |
To add to above, I get an error message: Error: Argument 1 can't be a list containing data frames
Hi! This was a quick script I put together to help a student many years ago to import her data into R. Haven’t looked at it in ages, so I am terribly sorry that I am a bit too rusty about it to respond or help debug without looking at it from scratch. Unfortunately, it doesn’t look like I’ll have the time to do so in the immediate future... will reach out to you if I do. My apologies once again! M
…--- Madhu
On 14 Feb 2020, 7:12 PM +0530, ginskr ***@***.***>, wrote:
To add to above, I get an error message: Error: Argument 1 can't be a list containing data frames
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
To add to above, I get an error message: Error: Argument 1 can't be a list containing data frames
Hi, what if my data is not contained under waypoints, but under tracks - how to expand that part into a dataframe?
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]]
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
Hi, what if my data is not contained under waypoints, but under tracks - how to expand that part into a dataframe?