By Paul Markley | July 28, 2022

Convert dataframe of coordinates to GPX format in four steps

Often, one may have a data frame of locations with attributes such as species names and may wish to create a GPX file from this data to use with a navigation software such as a GPS device. This can be achieved in four steps as follows:

Step 1: Load R library and dataframe


x <- data.frame(NAME=c("Species1", "Species2", "Species3"),
                LAT=c(70.11, 70.032145, 68.619535),
                LON=c(-148.52, -148.640821, -149.556137))

Step 2: Create a spatial vector from the dataframe

v <- vect(x, geom=c("LON", "LAT"), crs="+proj=longlat +datum=WGS84")

Step 3: Write the spatial vector to file in GPX format

writeVector(v, "~/GPS_wapoints.gpx", filetype="GPX", layer="waypoints", 
            overwrite=TRUE, options="GPX_USE_EXTENSIONS=yes")

Step 4: Upload file to GPS device

Connect your GPS device to a computer, and drag and drop the new file in the GPX folder of your GPS device. That’s it!


Back to Top ↑


Back to Top ↑


Back to Top ↑