Use the ogr2ogr command line tool, that is distributed with QGIS. In Windows, open the OSGeo4W Shell from the QGIS program group and enter
for %p in (path_to_gpx_files\*ride*.gpx) do ogr2ogr path_for_output\gpx.shp -append %p track_points -fieldTypeToString DateTime
The equivalent command in a Unix bash shell would be
for file in path_to_gpx_files/*ride*....
I think the easiest way is to use the Plugin Join Multiple Lines, either for connected or unconnected lines (as you see in the example below, in the latter case lines will be joined!)..
Save gpx-segments to a shapefile
Select segments & run plugin
Check result and save back to gpx
Another approach would be to load the data to a SpatiaLite DB and then ...
If it were a single feature to export you could use an action with canvas scope (i.e., interacting with the canvas), but since you may export several features, an action with layer scope fits better.
from qgis.utils import iface
from qgis.core import QgsProject, QgsVectorFileWriter, QgsCoordinateReferenceSystem
path = "/tmp/gpx/sample....
Try using v.generalize tool from the Processing Toolbox. There are a number of algorithms in there that can generalize a line nicely.
Another possible solution could be the "Generalizer" plugin which was mentioned in this post, the plugin info in QGIS suggests that the tool is based on the v.generalizer Grass module anyway.
Just for reference below ...
You can do Layer... Save As... and choose the CSV output format. Choose Geometry type as POINT and Geometry as AS_XY:
Then you'll get a CSV like:
here is my simple approach:
create a new map in umap: http://umap.openstreetmap.fr/en
click Import Data a select all the gpx files you have and upload them into map (you can import all of them at once)
enter Edit map settings > Default properties, choose opacity 0.25, weight 10.
The three steps above will take 5 minutes and here is the result:
Yes, there are such algorithms (see for example here, there and here) but since you seem to have only one single road, would it not be easier to do it by hand? (!). Using for example QGIS, you could import your GPS traces, create a new layer, digitalise the centerline of the bundle, and then export it in whatever format.
Download GPSBabel - for Ubuntu just use:
sudo apt-get install gpsbabel
With this command you will get a .gpx file of all track points with the speed (meter/second):
gpsbabel -t -i gpx -f input.gpx -x track,speed -o gpx -F output.gpx
please see comment by drnextgis - the command requres the addition of ',gpxver=1.0' and should therefore be as ...
Using Add Vector layer you can select multiple files by mouseclicking (at least on Windows), but you have to select for each GPX file what layer you want to add (most probably "tracks").
I guess this could be a good idea for a selfmade plugin, but I have not yet found the time to do that.
ptrv/gpx2spatialite does this remarkably well, saving timestamps for all points and deriving speed and length data for tracks. It also won't import duplicate tracks, so you can feed it a huge pile for GPX files and it will munge them appropriately.
Update: usage examples, as requested:
Initialize new database:
Add a ...
One option would be to compare the algorithms to your GPS tracks using a program such as GPS Visualizer. This program allows you to incorporate the best available DEM elevation data (i.e. usually 30m resolution) with your GPS data to produce an elevation profile. From there simply compare the min/max/range etc.
You can't modify GPX data in QGIS. Though GDAL supports GPX writing, this support is limited to creation only, modification of existing files is not supported.
Moreover, GPX is a format with specific structure, so you can't just add ANY field to it unless you use Extensions, but again, QGIS doesn't support this either.
You might want to save as ESRI Shape ...
I've ended up using gpsbabel which provides a GUI along with the command.
sudo apt-get install gpsbabel-gui
This will install the command gpsbabel as well.
You can follow the GUI settings, it's easy, in my case I removed all the extra options to convert tracks and routes (I was interested only in waypoints).
Otherwise the command is the ...
With gpxpy no, but with simple Python yes
Using the example of the PyPi page
print('Created GPX:', gpx.to_xml())
with open("output.gpx", "w") as f:
(gpxpy uses lxml or elementtree to parse .gpx files (in parser.py file))
Here is my approach on QGIS. This was for a set of bus routes, and I wanted to identify which roads had the most density of bus routes passing by.
Used the Qchainage plugin to convert my lines into points. Tested different scenarios until I produced a lot of points per line (1,500 per line, and lines were about 9kms).
Applied the heatmap symbology rendering ...
I know this is very late but it might help someone else...
I had exactly similar problem. I had to create a python script. Later on, I decided to contribute by creating a QGIS plugin.
What the plugin does is, it creates a single QGIS vector layer out of all GPX files in a selected path. You can convert the features into points, polygons or lines. You can ...
You could use the following code in your Python console. Load the .gpx file into QGIS and change the result_path to your desired location:
result_path = "C:/Users/You/Desktop/Test/Results//"
for layer in QgsMapLayerRegistry.instance().mapLayers().values():
processing.runalg("gdalogr:convertformat", layer, 0, '', result_path + layer....
You should be able to do this task in a variety of GIS applications. Here's a step-by-step for QGIS.
Download QGIS from: http://www.qgis.org/
Import the KML or GPX polyline (Layer > Add vector layer...).
Import the elevation data (Layer > Add raster layer...)
Either: create a buffer area around the polyline (Vector >
Geoprocessing tools > Buffer(s))
This is certainly possible. Create a new shapefile by choosing New under the menu Layers and there you select Shapefile. In the options dialog you choose Line and WGS84 projection and press Ok. It will prompt you to save somwhere.
Now the newly created shapefile shows up in your layer list. Select it and toggle editing to on (the Pen icon on the toolbar, or ...
You have many solutions but you choose to use ogr and the GeoJSON format (you could have chosen Fiona and shapely or one of the many modules to parse gpx files: Pypi:gpx or to parse XML files).
1) Is there a more direct or idiomatic way to create this rectangle?
ogr is is verbose, look at Python GDAL/OGR Cookbook
With the GeoJSON format:
I did a presentation a few years ago where I developed a tool to take GPX points and create a line featureclass by rows where the speed is indicated as an attribute. You can symbolize the output by that field in ArcMap. Natural breaks seems to symbolize it well.
I just uploaded the tool to arcgis.com, you can download it here.
After you get the line, you ...
I'm working with our local cycling group to anonymise GPX files on two criteria (primarily for security). I've never come across a standard way of anonymising data but this satisfies two concerns of our members, while preserving accuracy along roads and speed information:
Personal locations, removing 'private' areas for individuals;
Obscuring timestamps so ...
I know this is late but it might help others one day. There is a QGIS plugin called Batch GPS Importer which I explained more in this answer.
The latest version can filter out files using prefix and suffix text.
I hope it helps.
writeOGR should be the way to go. I believe you were pretty close with the code you provided in the comments. However, adding a couple of things to the writeOGR function will help ensure that the file is written. If you add dataset_options="GPX_USE_EXTENSIONS=yes", then you will no longer get the error, "Creating Name field failed". Below is my example ...
The question is a bit vague, so I'm going to focus my answer specifically on how one would generate a LiDAR-derived DEM raster product from a GPX that (apparently) contains LiDAR elevation contours.
1) Add the GPX to QGIS using the Data Source Manager by choosing Vector -> File
1A) Pre-process/cleanup data (Likely out of scope for you)
1. Fix Geometries
I know that this has already been answered .. but I couldn't use the answer and kept coming back to this question on every google search I did. So I made a mini python program to make a bunch of .gpx files into one big file. Thus getting around the problem of loading multiple files. Hopefully this helps someone else.
Once you have your new gpx file load it ...
you can use this code:
# reading a GPX
in_path = os.path.join('C:\\','python','GPX','FeierabendrundeMitJakob.gpx')
# get the correct driver
in_driver = ogr.GetDriverByName('GPX')
# 0 means read-only. 1 means writeable.
places_source = in_driver.Open(in_path, 0)
# write the data to a shape file
out_file = os.path.join('...