banniere

Le portail francophone de la géomatique


Toujours pas inscrit ? Mot de passe oublié ?
Nom d'utilisateur    Mot de passe              Toujours pas inscrit ?   Mot de passe oublié ?

Annonce

GEODATA DAYS 2024

#1 Fri 07 October 2022 14:24

Alison
Participant occasionnel
Date d'inscription: 2 Sep 2019
Messages: 26

QGIS/Python: Linux standalone

Bonjour à tous,

Je suis en train de mettre en place un script PyQGIS en standalone sur un serveur avec une distribution Linux (Debian GNU) avec accès SSH.

Après avoir parcouru le livre de recette, j'ai trouvé ce script à utiliser :
https://docs.qgis.org/3.16/fr/docs/pyqg … .html#id10
(point 1.4.1)

Seulement, après exécution j’obtiens ce message d'erreur :

Code:

qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

Savez-vous comment résoudre ce problème SVP ?
Ce serait a priori un problème lié au display.

Hors ligne

 

#2 Mon 10 October 2022 11:21

Alison
Participant occasionnel
Date d'inscription: 2 Sep 2019
Messages: 26

Re: QGIS/Python: Linux standalone

Bonjour,

Bon... j'ai réussi à débloquer la situation en utilisant ce code (si ça peut aider certains) :

Code:

import sys
import os
from qgis.core import *
from qgis.analysis import QgsNativeAlgorithms

os.environ["QT_QPA_PLATFORM"] = "offscreen"

QgsApplication.setPrefixPath('/usr', True)
qgs = QgsApplication([], False)
qgs.initQgis()

sys.path.append('/usr/share/qgis/python/plugins/')

from qgis import processing
from processing.core.Processing import Processing
Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())

processing.run("native:intersection", {'INPUT':"WFS:// pagingEnabled='true' preferCoordinatesForWfsT11='false' restrictToRequestBBOX='1' srsname='EPSG:3857' typename='Accordes_ou_en_construction' url='http://data.geo-ide.application.developpement-durable.gouv.fr/WFS/943/eolien' url='http://data.geo-ide.application.developpement-durable.gouv.fr/WFS/943/eolien?request=GetCapabilities' version='auto'",'OVERLAY':'postgres://dbname=\'dbname\' host=host port=port user=\'user' password=\'password' sslmode=disable key=\'PGid\' srid=2154 type=MultiPolygon checkPrimaryKeyUnicity=\'1\' table="schema"."table" (geom)','INPUT_FIELDS':[],'OVERLAY_FIELDS':[],'OVERLAY_FIELDS_PREFIX':'','OUTPUT':'/root/alison/output_test.shp'})

Cela marche avec des SHP en input et overlay !

En revanche, quand je fais avec un flux WFS et une table d'un base PostGIS, ça ne marche pas... j'ai mis mon code ci-dessus (avec les infos serveur, mot de passe etc retirées) et il n'arrive pas à charger les layer.

Avez-vous une idée ?

Hors ligne

 

#3 Wed 12 October 2022 16:51

Alison
Participant occasionnel
Date d'inscription: 2 Sep 2019
Messages: 26

Re: QGIS/Python: Linux standalone

J'ai trouvé ma solution grâce à cette vidéo :

https://www.youtube.com/watch?v=0Am93XXXjxg

Bref... pyqgis est très capricieux sous Linux.
Il faut vraiment persévérer et trouver des solutions à droite à gauche...

Bon courage à ceux qui se lance dans cette aventure.

Hors ligne

 

Pied de page des forums

Powered by FluxBB