Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a plugin which will extract the gpx files and load them onto the active layer window in QGIS. While I'm able to load it using the QGIS GUI from Layer>New Vector Layer, I'm not able to make it happen from the python console.

You can find a screenshot of the error here.

I've tried using the following commands but in vain.

>>> qgis.utils.iface.addVectorLayer(path,'layer_name','gpx')


>>> vlayer = QgsVectorLayer(path[0],'new_layer','gpx')

did not display any error at the same time it did not appear in the list of active layers. Tried using setActiveLayer() but it returned False.

Any help or suggestions would be welcomed !


share|improve this question
up vote 2 down vote accepted

I've not tested it myself but the PyQGIS CookBook says that a type specifier is required.

Type may be set to track, route or waypoint.

The example from the cookbook:

uri = "path/to/gpx/file.gpx?type=track"
vlayer = QgsVectorLayer(uri, "layer_name_you_like", "gpx")
share|improve this answer
Thanks a ton Thomas!! Worked like a charm. – Allen Jan 8 '13 at 5:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.