Skip to content
Prev 6010 / 29559 Next

Problem with gdalOGR: GPX format

On Mon, 6 Jul 2009, Agustin Lobo wrote:

            
Yes, hard to understand, but that's ontology in the GIScience sense, it's 
certainly clear to the people who wrote it (I hope!). Try this:

library(sp)
load("fl1.rda")
pts <- spsample(fl1, n=50, offset=0.0, type="regular")
crds <- coordinates(pts)
SPDF <- SpatialPointsDataFrame(pts, data=as.data.frame(crds))
names(SPDF)
library(rgdal)
writeOGR(spTransform(SPDF, CRS("+proj=longlat +datum=WGS84")),
   dsn="fl1sp_pts.gpx", layer="waypoints", driver="GPX",
   dataset_options="GPX_USE_EXTENSIONS=yes")
summary(readOGR(dsn="fl1sp_pts.gpx", layer="waypoints"))

so three things: the GPX driver in OGR only seems to accept geographical 
coordinates; you needed layer="waypoints" - it accepts any value for 
writing, but readOGR() only takes the five enumerated on the OGR GPX page; 
and it is dataset_options="GPX_USE_EXTENSIONS=yes" (or YES), not 
layer_options=.

The last was the key problem, but it then failed on coordinates outside 
the range of geographical coordinates. The layer name is not used, so 
maybe best to stay with the most appropriate of the five values accepted 
for reading.

Roger