Skip to content

writeOGR to GPX file: empty table

6 messages · Roger Bivand, Agustin Lobo

#
Hi!,

I'm converting from shape to gpx through rgdal (I get an empty file with
gpsbabel and, according to its web, I'm not convinced that the shape format
is actually fully supported by gpsbabel).

This is what I do:
OGR data source with driver: ESRI Shapefile
Error in writeOGR(AilantMSY09, dsn =
"/media/TRANSCEND/MONTSENY2008/MONTSENY_GEODATA/FloraExotica2009/AilantMSY09GPX", 
: 
  
	GDAL Error 6: Field of name 'Comentario' is not supported in GPX schema.
Use GPX_USE_EXTENSIONS creation option to allow use of the <extensions>
element.

After reading the gdal-ogr doc, I include dataset_options:
Error in writeOGR(AilantMSY09, dsn =
"/media/TRANSCEND/MONTSENY2008/MONTSENY_GEODATA/FloraExotica2009/AilantMSY09GPX", 
: 
  
	GDAL Error 1: Latitude 4627933.603181 is invalid. Valid range is [-90,90].
This warning will not be issued any more

Which indicates that the user must unproject first (it seems that GPX files
only support lon,lat):
Warning message:
In spTransform(xSP, CRSobj) :
  Only x- and y-coordinates are being transformed
Once in QGIS, the points are in the right sites but the attribute table is
all NULLs

This is not a concern (by now) for me as I just need the gpx file to upload
the points to the gps unit,
but report it just in case this is a bug and/or to know if I'm doing
something wrong.

Note: I do get the correct table for the gpx file using plugin OGR converter
in QGIS.

Thanks

Agus
#
On Mon, 17 May 2010, Agustin Lobo wrote:

            
Please check the output GPX file in a text editor to see what is present 
there. Also please read the GPX file back into R with readOGR(), assuming 
that on your platform the OGR GPX driver has read support.

Roger

  
    
#
Roger,
There is actually information in the file, i.e. the first point is:

<?xml version="1.0"?>
<gpx version="1.1" creator="GDAL 1.6.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ogr="http://osgeo.org/gdal" xmlns="http://www.topografix.com/GPX/1/1"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd">
<wpt lat="41.800745980899059" lon="2.359550956673553">
  <extensions>
    <ogr:Comentario>4</ogr:Comentario>
    <ogr:Rcvr_Type>Juno ST</ogr:Rcvr_Type>
    <ogr:GPS_Date>2009/10/27</ogr:GPS_Date>
    <ogr:GPS_Time>03:09:11pm</ogr:GPS_Time>
    <ogr:Datafile>AILANTO27102009.SSF</ogr:Datafile>
    <ogr:GPS_Height>1089.392</ogr:GPS_Height>
    <ogr:Northing>4627933.603</ogr:Northing>
    <ogr:Easting>446791.833</ogr:Easting>
    <ogr:PDOP_max>0</ogr:PDOP_max>
    <ogr:HDOP_max>0</ogr:HDOP_max>
    <ogr:Fecha_GPS>0000/00/00</ogr:Fecha_GPS>
    <ogr:PosNofilt>0</ogr:PosNofilt>
    <ogr:Pos_filt>0</ogr:Pos_filt>
    <ogr:Semana_GPS>0</ogr:Semana_GPS>
    <ogr:Segundo_GP>0</ogr:Segundo_GP>
    <ogr:Altura_GPS>0</ogr:Altura_GPS>
    <ogr:Prec_vert>0</ogr:Prec_vert>
    <ogr:Prec_horz>0</ogr:Prec_horz>
    <ogr:Dev_Tp>0</ogr:Dev_Tp>
    <ogr:Norte>0</ogr:Norte>
    <ogr:Este>0</ogr:Este>
    <ogr:Abundancia>4</ogr:Abundancia>
  </extensions>
</wpt>

Cannot read it in R. Maybe I'm not using the appropriate settings for dsn
and layer (I've tried
many alternatives):
Cannot open layer

Agus
#
On Mon, 17 May 2010, Agustin Lobo wrote:

            
The variants are as described in the readOGR help file, that is layer=
"waypoints", "tracks", "routes", "track_points", or "route_points". Maybe 
reading the help page might save time??

Roger

PS. I think that the OGR GPX driver expects a number of fields that are 
most often absent when reading (so generating NULL/NA), and may not handle 
other extra user-defined fields gracefully. If need be, create a short 
string in the NAME or name field to concatenate the data you need, that is 
work around apparent shortcomings in the driver.

  
    
#
Sorry about not having read the doc, I'm probably too used to import shape
files
with readOGR() and did not realize that GPX files would have different
options.

test <-
readOGR(dsn="/media/TRANSCEND/MONTSENY2008/MONTSENY_GEODATA/FloraExotica2009/AilantMSY09R.gpx",layer="waypoints")

works fine and the table is correct. I think that 
dataset_options="GPX_USE_EXTENSIONS=YES"
at writing did the job.

So no problem at all with writing/reading GPX files in R through rgdal
I would add a line to the help page reminding the user that coordinates must
be geographic in GPX
files (thus the user must eventually unproject before writeOGR() ).

Thanks!

Agus
#
On Mon, 17 May 2010, Agustin Lobo wrote:

            
OK, will do.

Roger