Exporting to GPX file

Viewed 81

When I import a .gpx file from my naviagation software into r using the gpx package it arrives in this format

dput(test)
list(routes = list(structure(list(Elevation = c(NA_real_, NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
NA_real_), Time = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), class = c("POSIXct", 
"POSIXt"), tzone = "UTC"), Latitude = c(50.76098, 50.76327, 50.766489, 
50.771325, 50.771792, 50.773814, 50.774321, 50.774669, 50.775666, 
50.774327), Longitude = c(-1.322124, -1.32737, -1.324514, -1.316833, 
-1.314606, -1.300727, -1.294736, -1.290568, -1.27571, -1.263494
), extensions = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), class = "data.frame", row.names = c(NA, 
-10L))), tracks = list(structure(list(Elevation = logical(0), 
    Time = logical(0), Latitude = logical(0), Longitude = logical(0)), class = "data.frame", row.names = integer(0))), 
    waypoints = list(structure(list(Elevation = logical(0), Time = logical(0), 
        Latitude = logical(0), Longitude = logical(0)), class = "data.frame", row.names = integer(0))))

What I want to do is export a gpx back to the same software. I have tried using the pgirmess package but it no longer supports the writeGPX command seemingly.

Then I tried to manipulate the answer given in this question here R Convert GPS to GPX with timestamp

but I am not looking to export a track but a route for people to follow so the timestamp is not relevant.

I also tried using the rgdal package as shown below.

my data


dput(routes)
list(structure(list(Elevation = c(NA_real_, NA_real_, NA_real_, 
NA_real_, NA_real_, NA_real_), Latitude = c(50.768333, 50.771833, 
50.7735, 50.769167, 50.77, 50.769167), Longitude = c(-1.307167, 
-1.295833, -1.292667, -1.286667, -1.295833, -1.2775), Name = c("3X Donna", 
"3Z Trinity House Buoy", "33 Prince Consort", "34 Cowes Corinthian", 
"39 Snowden", "4K Royal London YC")), class = "data.frame", row.names = c(53L, 
55L, 58L, 59L, 60L, 70L)))

The I run the code below but still no joy

library(rgdal)

coordinates(routes) <- ~Latitude+Longitude
  proj4string(routes) <- "+proj=longlat +datum=WGS84" 

writeOGR(routes, dsn = "routes.gpx", layer = "routes", driver = "GPX", 
         dataset_options = "GPX_USE_EXTENSIONS=yes")

I would like ideally to export a route not a track.

0 Answers
Related