[Qgis-user] Problem with loading layers from a project

James Keener jim at jimkeener.com
Thu Apr 30 22:34:14 PDT 2015


I'm trying to load a project via python (original project and the single
shp file (the extension should be .zip), along with the project after
saving, are attached).  When I load the project, there are no layers,
and if I write the project out, it doesn't contain the original layer
either.

Python transcript:
> jim at lilith {+81% } Fri 2015-05-01 01:16:00 0                                                                                                                                                    
> /home/jim/Desktop/test
> % export PYTHONPATH=/usr/share/qgis/python
> jim at lilith {+82% } Fri 2015-05-01 01:16:02 0                                                                                                                                                    
> /home/jim/Desktop/test
> % python                                  
> Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
> [GCC 4.8.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from qgis.core import QgsProject
>>>> from PyQt4.QtCore import QFileInfo
>>>> project = QgsProject.instance()
>>>> project.read(QFileInfo('test.qgs'))
> True
>>>> map(lambda i: i.name(), project.layerTreeRoot().children())
> []
>>>> project.write()
> True

Before and After sizes:
> jim at lilith {+81% } Fri 2015-05-01 01:15:14 0                                                                                                                                                    
> /home/jim/Desktop/test
> % ls -l test.qgs
> -rw-rw-r-- 1 jim jim 14222 May  1 01:15 test.qgs
> jim at lilith {+82% } Fri 2015-05-01 01:16:20 0                                                                                                                                                    
> /home/jim/Desktop/test
> % ls -l test.qgs
> -rw-rw-r-- 1 jim jim 1654 May  1 01:17 test.qgs

I'm sure (or at least hope!) that I'm just doing something little (and
non-obvious?) wrong.

As an aside: this is a condensed test.  If you add a group into the
project, the group will show up in the layer list and will be written
back out, but no other layers will be found.

Thank you,
Jim

PS:

contents of PYTHONPATH, in case I'm not using the right location

> jim at lilith {+90% } Fri 2015-05-01 01:28:05 0                                                                                                                                                    
> /home/jim/Desktop/test
> % ls -l $PYTHONPATH 
> total 20
> drwxr-xr-x 2 root root 4096 Feb 26 10:46 console/
> drwxr-xr-x 6 root root 4096 Feb 26 10:46 owslib/
> drwxr-xr-x 7 root root 4096 Aug 20  2014 plugins/
> drwxr-xr-x 2 root root 4096 Feb 26 10:46 pyplugin_installer/
> drwxr-xr-x 2 root root 4096 Feb 26 10:46 qsci_apis/


I had seen somewhere about doing QgsApplication.initQgis(), so I gave
that a shot:

> % python
> Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
> [GCC 4.8.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from qgis.core import QgsApplication
>>>> from qgis.core import QgsProject
>>>> from PyQt4.QtCore import QFileInfo
>>>> QgsApplication.setPrefixPath('/usr/share/qgis', True)
>>>> QgsApplication.initQgis()
>>>> project = QgsProject.instance()
>>>> project.read(QFileInfo('test.qgs'))
> True
>>>> map(lambda i: i.name(), project.layerTreeRoot().children())
> []

to no avail :(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.qgs
Type: application/x-qgis-project
Size: 14222 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20150501/d69e405b/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Hospitals.really-a-zip
Type: application/zip
Size: 8405 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20150501/d69e405b/attachment.zip>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20150501/d69e405b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20150501/d69e405b/attachment.sig>


More information about the Qgis-user mailing list