I'm trying to download the location plan for each point on my network. This will allow me to fill in a data sheet with a GIS photo with the manhole in the center.
I've managed to find out how to download the current QGIS canvas and adjust the zoom level.
My problem is that the capture is made before QGIS moves my point. I did some tests by putting my canvas in an unknown location before launching my python script. The resulting image is the image of the location i chose at random before qgis centers the canvas on my point.
The consequence is that when I switch to prod the canvas capture is not just because it's on the previous point.
I hope i've made myself clear.
Here's a test file: https://www.grosfichiers.com/4DEs3Rdment
from qgis.core import *
from PyQt5.QtCore import QDateTime, QTimer
import os
from qgis.utils import iface
# Récupérer l'instance du projet
project = QgsProject.instance()
regards = project.mapLayersByName("fiche_regard fiche_reg")[0]
# Créer un répertoire si nécessaire
output_dir = "R:/Commun/Eliezer/developpement en cours/fiche_SAUR/"
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# Récupérer les entités (features) de la couche et les convertir en liste
def capture_plan(nom_image):
point_geom = QgsGeometry.fromPointXY(QgsPointXY(495521.80476182291749865, 6913526.50558853521943092))
# Récupérer les coordonnées du point
point = point_geom.asPoint()
iface.mapCanvas().saveAsImage(os.path.join(output_dir, f"{nom_image}.jpg"))
buffer_size = 21
extent = iface.mapCanvas().extent()
extent.setXMinimum(point.x() - buffer_size)
extent.setXMaximum(point.x() + buffer_size)
extent.setYMinimum(point.y() - buffer_size)
extent.setYMaximum(point.y() + buffer_size)
# Appliquer l'extension et rafraîchir la carte
iface.mapCanvas().setExtent(extent)
iface.mapCanvas().refresh()
QgsApplication.processEvents() # Forcer le traitement des événements
capture_plan("PAR_REG_578")