3

I want to add a feature class of a personal geodatabase mdb to my qgs project by code (a plugin I am working on).

I am using a command similar to that used for adding shapefiles, but this is not working. I guess there must be a way, since it is possible to add the layer using the Add Vector Layer button.

This is the code i am using on the Python console:

mylayer = QgsVectorLayer("D:\Test\test.mdb\points", "mypoints", "ogr")
QgsMapLayerRegistry.instance().addMapLayer(mylayer)

The first line runs without error but the second one does not produce any result, contrary to the result is I do a similar command using a shapefile.

I am using QGIS 2.2 Valmiera 32 bits on Windows 7 64 bits. I did a previous research but I did not find any results!!! The feature class is not inside a feature dataset.


I guess I would have to use a QgsDataSourceURI(), but i can not figure out the syntax. I have been trying. Also, I would also want to add that migrating the mdb is not an option, I have requested this before but my superiors have refused. And this geodatabase (points) is updated daily and huge. My goal after loading is clipping it based on a zone of interest.

2

Well is was easier than expected, not ODBC stuff, just the following code:

mylayer = QgsVectorLayer(r"D:\Test\test.mdb|layername=points", "mypoints", "ogr")
QgsMapLayerRegistry.instance().addMapLayer(mylayer)

I hope it will work on the newer versions of QGis.

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.