2

This is my first script and I having a problem trying to clip a shp file.

I'm running on a linux server and this is my code:

 #! python 

from datetime import date
from qgis.core import *
from PyQt4.QtGui import *
import sys

#disable gui
qgs = QApplication([], False)

#call qgis
QgsApplication.setPrefixPath("/usr/bin/qgis", True)

#scrip start

QgsApplication.initQgis()

#call processing plugin
sys.path.append("/usr/share/qgis/python/plugins")
from processing.core.Processing import Processing
Processing.initialize()
from processing.tools import *
import processing

#centroamerica
centroamerica = QgsVectorLayer("/pronosticos/centroamerica/ca.shp", "Centroamerica")

#date
date = date.today().strftime('%Y%m%d')

#global data

precipitacion_24h = QgsVectorLayer("/pronosticos/global/gfs_precip_shp_tif_" + date + "/gfs_precip_gis_24_" + date + ".shp", "Precipitacion 24 horas")

#clip
processing.runalg('qgis:clip', precipitacion_24h, centroamerica,'/pronosticos/salidas/precipitacion_24h.shp')

# Exit applications
QgsApplication.exitQgis()
QApplication.exit()

I got this message:

 python clip.py
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
Traceback (most recent call last):
  File "clip.py", line 51, in <module>
    processing.runalg('qgis:clip', precipitacion_48h, centroamerica, "/pronosticos/salidas/precipitacion_48h.shp")
  File "/usr/share/qgis/python/plugins/processing/tools/general.py", line 66, in runalg
    alg = Processing.runAlgorithm(algOrName, None, *args)
  File "/usr/share/qgis/python/plugins/processing/core/Processing.py", line 305, in runAlgorithm
    if not alg.checkInputCRS():
  File "/usr/share/qgis/python/plugins/processing/core/GeoAlgorithm.py", line 292, in checkInputCRS
    layers = QGisLayers.getAllLayers()
  File "/usr/share/qgis/python/plugins/processing/core/QGisLayers.py", line 93, in getAllLayers
    layers += QGisLayers.getRasterLayers();
  File "/usr/share/qgis/python/plugins/processing/core/QGisLayers.py", line 69, in getRasterLayers
    layers = QGisLayers.iface.legendInterface().layers()
AttributeError: 'NoneType' object has no attribute 'legendInterface'
6
  • I tried this in my local computer and i works fine using PyQGIS in qgis 2.18 Oct 12, 2018 at 14:22
  • The clip algorithm seems to use the iface variable, which exists inside qgis but not in a standalone script. But i don't why and what it wants to do with raster layers? Oct 12, 2018 at 22:00
  • Hi Andreas, I’m not using raster layers, both are shapefiles Oct 13, 2018 at 23:46
  • I know, but the stacktrace shows that clip uses raster functuons, seems weird to me. Oh, and you say linux server, is qgis installed on this, too? Linux server often omit gui based software. Oct 14, 2018 at 7:44
  • 1
    I tried your script with slight modifications, i am on wondows, and it works for me. So i can't give an answer here. Problem might be on QgsVectorLayer where you leave out a third parameter, the provider name "ogr". But i think you are missing libraries on your linux installation, as the error messages suggest. May be it would better to change your question and hint to linux server platform! Oct 14, 2018 at 10:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.