[Qgis-user] Invalid data source loading vector layer using PyQGIS

Noli Sicad nsicad at gmail.com
Fri Apr 22 17:32:05 PDT 2011


Hi Mathieu

Have a look at this QGIS plugin - Load Them All, a QGIS plugin

http://geotux.tuxfamily.org/index.php?option=com_content&task=view&lang=en&id=264

Download and install, then see how the shapefile is retrieved in this plugin.

Noli

On 4/23/11, Mathieu Coudert <mathieu.coudert at gmail.com> wrote:
> Hi list,
>
> I'm trying to load a vector layer (shapefile) using PyQGIS and especially
> QgsVectorLayer constructor.
> I had a look at the following link to start with :
> http://www.qgis.org/pyqgis-cookbook/intro.html#python-applications
> and also :
> http://www.qgis.org/pyqgis-cookbook/loadlayer.html#vector-layers
>
> So my script looks like :
>
> *QgsApplication.setPrefixPath("/usr",True)*
> *QgsApplication.initQgis()*
> *myLayer = QgsVectorLayer("/tmp/data.gboundaries.shp","gboundaries","ogr")*
>
> But I get this error message : "Data source is invalid" and my layer is
> invalid.
>
> However, it is working when I launch it in the QGIS python console.
>
> Do I need to set/export any variable outside of QGIS to use the ogr
> provider?
> Does anybody has any clue about my problem?
>
> FYI, I'm working on Ubuntu 10.10, with Python 2.6 and QGIS 1.6 (from the
> packages).
>
> Thanks for your help,
>
> Cheers,
>
> Mathieu
>



More information about the Qgis-user mailing list