[R-sig-Geo] Problem with gdalOGR: GPX format
Agustin Lobo
alobolistas at gmail.com
Mon Jul 6 11:36:58 CEST 2009
Thanks,
I've just circumvented the problem by writing a "universal csv" file (in
gpsbabel jargon, see:
http://www.gpsbabel.org/htmldoc-development/fmt_unicsv.html
using write.table() and having converted to lon,lat and wgs84 with
spTransform() first.
Then I convert to compegps format (the format used by the UAV navigation
system) using gpsbabel,
GPX was an intermediate format between OGR and gpsbabel. unicsv seems
easier to manage!
Agus
Roger Bivand wrote:
> 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
>>
>
More information about the R-sig-Geo
mailing list