[Qgis-user] Problem loading vector layer in python

2011-07-05 Thread Viktor Kalén
Hi,

I'm having problem loading a vector (shape) layer from python, (as
decribed in this document:
http://www.scribd.com/doc/56229514/4/Python-Applications , page 7)


Heres my code:


def main():
pass

if __name__ == '__main__':
main()

import sys, os

from qgis.core import *
import qgis.utils


QgsApplication.setPrefixPath(C:\OSGeo4W\apps\qgis, True)
QgsApplication.initQgis()



vlayer = QgsVectorLayer(C:\test_qgis\ROG_Kommuner.shp,test_layer,ogr)


if not vlayer.isValid():
print Layer failed to load!




and the output reporting that my layer failed to load:

*** Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32
bit (Intel)] on win32. ***

Layer failed to load!



I'm using the OSGeo4W installation, on Windows 7, python 2.52, 32 bit.
I'm using pyscripter.

What am I doing wrong here?


Viktor Kalén
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-user


Re: [Qgis-user] Problem loading vector layer in python

2011-07-05 Thread Richard Duivenvoorde
On 07/05/2011 12:40 PM, Viktor Kalén wrote:
 Layer failed to load!
 I'm using the OSGeo4W installation, on Windows 7, python 2.52, 32 bit.
 I'm using pyscripter.
 
 What am I doing wrong here?

Hi Viktor,

tried your lines here on linux. And layer was valid.

Did you set all paths ok see also:
http://www.qgis.org/pyqgis-cookbook/intro.html

It's easier testing by just testing line by line:
Start python and start with the line:
import sys, os
then try line by line

it will throw errors on the lines that are failing (for mine eg it was
that I first had to set the PYTHONPATH and LD_LIBRARY_PATH. But after
that all was fine.

Regards,

Richard Duivenvoorde
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-user