[R-sig-Geo] Problem with gdalOGR: GPX format
Roger Bivand
Roger.Bivand at nhh.no
Mon Jul 6 11:05:04 CEST 2009
On Mon, 6 Jul 2009, Agustin Lobo wrote:
> I'm trying to write an SpatialPointsDataFrame object as
> GPX. I do:
>>
> writeOGR(wpcast1SPDF,dsn="/media/Transcend/MONTSENY2008/MONTSENY_UAV2/GPX",layer="wpcast1lonlat",driver="GPX")
> Error in writeOGR(wpcast1SPDF, dsn =
> "/media/Transcend/MONTSENY2008/MONTSENY_UAV2/GPX", :
>
> GDAL Error 6: Field of name 'coords.x1' is not supported in GPX
> schema.
> Use GPX_USE_EXTENSIONS creation option to allow use of the <extensions>
> element.
>
> Which would be valid Field of name 'coords.x1'? I've tried reading
> http://www.topografix.com/GPX/1/1/
> but it's really hard to understand.
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
>
> I've also tried to add layer_options="GPX_USE_EXTENSIONS=YES" according to
> http://www.gdal.org/ogr/drv_gpx.html
> "GPX_USE_EXTENSIONS: By default, the GPX driver will discard attribute
> fields that do not match the GPX XML definition (name, cmt, etc...).
> If GPX_USE_EXTENSIONS=YES is specified, extra fields will be written
> inside the<extensions> tag."
>
> but still get the same error (and, ultimately, I'm not sure this would
> actually solve the problem, the best would be using the "valid Field of
> name coords.x1"):
>
> writeOGR(wpcast1SPDF,dsn="/media/Transcend/MONTSENY2008/MONTSENY_UAV2/wpscastlonlat.gpx",layer="wpcast1lonlat",driver="GPX",layer_options="GPX_USE_EXTENSIONS=YES")
> Error in writeOGR(wpcast1SPDF, dsn =
> "/media/Transcend/MONTSENY2008/MONTSENY_UAV2/wpscastlonlat.gpx", :
>
> GDAL Error 6: Field of name 'coords.x1' is not supported in GPX
> schema.
> Use GPX_USE_EXTENSIONS creation option to allow use of the <extensions>
> element.
>>
>
> Any help appreciated,
> Agus
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list