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@lilith {+81% } Fri 2015-05-01 01:16:00 0                                  
>                                                                               
>                                     
> /home/jim/Desktop/test
> % export PYTHONPATH=/usr/share/qgis/python
> jim@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@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@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@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 :(

Attachment: test.qgs
Description: application/qgis-project

Attachment: Hospitals.really-a-zip
Description: Zip archive

+proj=longlat +datum=WGS84 +no_defs EPSG:4326 3452 false 0 255 255 255 255 255 255 2 current_layer off 0 2 true false

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Qgis-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to