7

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

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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