The following script works fine from python or ipython at the command line:
from qgis.core import *
from qgis.gui import *
import sys
sys.path.append("/usr/share/qgis/python/plugins")
from PyQt4.QtCore import *
from PyQt4.QtGui import *
app = QgsApplication([], True)
QgsApplication.initQgis()
from processing.core.Processing import Processing
Processing.initialize()
import processing
layer = QgsVectorLayer('ger.shp','ger','ogr')
Where ger.shp
is a shapefile in the current folder. After this, layer.isValid()
is True. No warnings or messages.
But if I try and run it from the rPython
package, I get an error message and the layer is not valid:
library(rPython)
qtest <- function(){
code = "from qgis.core import *
from qgis.gui import *
import sys
sys.path.append('/usr/share/qgis/python/plugins')
from PyQt4.QtCore import *
from PyQt4.QtGui import *
app = QgsApplication([], True)
QgsApplication.initQgis()
from processing.core.Processing import Processing
Processing.initialize()
import processing
layer = QgsVectorLayer('ger.shp','ger','ogr')
"
rPython::python.exec(code)
}
qtest()
QObject::connect: Cannot connect (null)::raiseError( QString ) to QgsVectorLayer::raiseError( QString )
and then:
python.get("layer.isValid()")
[1] FALSE
It is identical code and identical python version, so I think it can only be in the way the code is run - perhaps the python interpreter is initialised differently from the way embedded python is run in rPython? I'm stuck.