[gdal-dev] convert 2 shapefiles to a single GPX?

Even Rouault even.rouault at mines-paris.org
Sun Mar 29 14:26:22 EDT 2009


Duarte,

yes I could reproduce your error too... In fact, depending on the source 
directory, you could observe that sometimes it works, sometimes it doesn't... 
The main reason is that ogr2ogr doesn't get the layers in the order you 
specify them on the command line. I've always made this wrong assumption, but 
the current state of ogr2ogr simply rely on the order in which they are 
exposed by the source dataset (and for a shapefile dataset, it is the order 
in which the filesystem lists the files of the directory, which is 
unspecified). Maybe we should correct ogr2ogr behaviour, so that is iterates 
on the source layers in the order in which they are specified...

In the meantime, I've come with a workaround using OGR VRT.

Save the following content as gpxdir.vrt for example, at the same level of 
your gpxdir directory.

<OGRVRTDataSource>
    <OGRVRTLayer name="waypoints">
        <SrcDataSource>gpxdir</SrcDataSource> 
        <SrcLayer>waypoints</SrcLayer> 
        <GeometryType>wkbPoint</GeometryType> 
        <LayerSRS>WGS84</LayerSRS>
    </OGRVRTLayer>
    <OGRVRTLayer name="tracks">
        <SrcDataSource>gpxdir</SrcDataSource> 
        <SrcLayer>tracks</SrcLayer> 
        <GeometryType>wkbLineString</GeometryType> 
        <LayerSRS>WGS84</LayerSRS>
    </OGRVRTLayer>
</OGRVRTDataSource>

Then run :
ogr2ogr -f GPX -dsco GPX_USE_EXTENSIONS=YES merged.gpx 
gpxdir.vrt -skipfailures -lco FORCE_GPX_TRACK=TRUE

Best regards,
Even

Le Sunday 29 March 2009 19:51:31 Duarte Carreira, vous avez écrit :
> Even,
>
> I'm not having luck with the command to merge 2 gpx files. It always
> discards the points with many errors like this: ERROR 6: Cannot write a
> 'wpt' element after a 'trk' element.
>
> I am sure I'm using the correct order in the command, and the correct
> files. ogr2ogr -f GPX -dsco GPX_USE_EXTENSIONS=YES merged.gpx gpxdir
> waypoints tracks -skipfailures -lco FORCE_GPX_TRACK=TRUE
>
> I have added FORCE_GPX_TRACK=TRUE because the error before adding this
> referred to rte elements, and my lines are multilinestrings.
>
> Duarte
>
> ________________________________________
> De:Duarte Carreira
> Mon, 19 Jan 2009 02:04:29 -0800
> RE: [gdal-dev] convert 2 shapefiles to a single GPX?
>
>
> Now this I've got to try!
>
> The VRT file idea is intriguing. I didn't know it had this much
> flexibility...
>
> Thanks,
> Duarte
>
> -----Mensagem original-----
> De: Even Rouault
> [mailto:even.roua... at mines-paris.org<mailto:even.roua... at mines-paris.org>]
> Enviada: sábado, 17 de Janeiro de 2009 20:43
> Para: gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>
> Cc: Duarte Carreira; Stefan Keller; Jean-Claude Repetto
> Assunto: Re: [gdal-dev] convert 2 shapefiles to a single GPX?
>
> Here's one solution :
>
> 1) create a directory, for example "merge_shp"
> 2) copy in merge_shp the shapefile that is going to be put in the waypoints
> layer as "waypoints.shp" (rename the .dbf and .shx accordingly)
> 3) copy in merge_shp the shapefile that is going to be put in the tracks
> layer as "tracks.shp" (rename the .dbf and .shx accordingly)
> 4) run "ogr2ogr -f GPX merged.gpx merge_shp waypoints tracks" (the order of
> the layers is important)
>
> A solution based on an OGR VRT file defining the two layers from the 2
> shapefiles would also probably work.
>
> Le Thursday 15 January 2009 12:03:27 Duarte Carreira, vous avez écrit :
> > Maybe the same approach can be used with 2 gpx files? That would be very
> > good. I cannot merge 2 shapefiles with different geometry types. I could
> > convert line shape>gpx1 and point shape->gpx2 and then merge
> > gpx2+gpx2->gpx3...
> >
> >
> > Thanks,
> > Duarte
> >
> > De: Stefan Keller [mailto:sfkel... at gmail.com<mailto:sfkel... at gmail.com>]
> > Enviada: quarta-feira, 14 de Janeiro de 2009 22:40
> > Para: Jean-Claude Repetto
> > Cc: Duarte Carreira;
> > gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org> Assunto: Re:
> > [gdal-dev] convert 2 shapefiles to a single GPX?
> >
> >
> > A merge of two shapefiles 'file1.shp' and 'file2.shp' into a new file
> > 'file_merged.shp' is performed like this (See
> > http://www.gdal.org/ogr/drv_shapefile.html):
> >
> > % ogr2ogr file_merged.shp file1.shp
> > % ogr2ogr -update -append file_merged.shp file2.shp -nln file_merged
> >
> > Then convert to GPX:
> > % ogr2ogr -f "GPX" out.gpx file_merged.shp
> >
> > Stefan
> > http://geoconverter.hsr.ch<http://geoconverter.hsr.ch/>
> > 2009/1/14 Jean-Claude Repetto
> > <jrepe... at free.fr<mailto:jrepe... at free.fr><mailto:jrepe... at free.fr<mailto
> >:jrepe... at free.fr>>> Duarte Carreira a écrit :
> >
> > Can OGR convert 2 shapefiles to a single GPX?
> >
> > The objective is to add tracks from a line shapefile and waypoints from a
> > point shapefile...
> >
> > Hello,
> >
> > I don't know the answer to your question, but since GPX files are text
> > files, it is very easy to merge two GPX files with a text editor.
> >
> > HTH !
> > Jean-Claude
> >
> >
> >
> > _______________________________________________
> > gdal-dev mailing list
> > gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org><mailto:gdal-dev
> >@lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>>
> > http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev




More information about the gdal-dev mailing list