Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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')

But,

>>> 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 !

Thanks

share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.