0

The vertex tool in red and the geometry displayed by the layer in yellow are not in sync

enter image description here

from time import sleep
from qgis.PyQt.QtSql import QSqlQuery, QSqlDatabase
serverName = 'hostname'
database = 'dbname'
port = 'port'
usr = 'username'
pw = 'password'
uri = QgsDataSourceUri()
uri.setConnection(serverName, port, database, usr, pw)

def stopped(task):
    pass
def completed(exception, result=None):
    pass
def run(task, wait_time):
    # main code    
    wait_time = wait_time / 100

    Layers= ['120_pipes']

    for i, lyr in enumerate(Layers):
        task.setProgress(i)
        sleep(wait_time)
        uri.setDataSource('120', lyr, "wkb_geometry")
        vlayer = QgsVectorLayer(uri.uri(), lyr, "postgres")
        if vlayer.isValid():
            g = QgsProject.instance().layerTreeRoot().insertGroup(0, '120')
            QgsProject.instance().addMapLayer(vlayer, False)
            g.insertChildNode(0, QgsLayerTreeLayer(vlayer))

        if task.isCanceled():
            stopped(task)
            return None

task = QgsTask.fromFunction(u'Task', run,
                            on_finished=completed, wait_time=50)
QgsApplication.taskManager().addTask(task)
  • It looks like the problem is that after you move a vertex with the Vertex Tool, the tool "remembers" where the vertices used to be, and can't detect them at their new location. Can you confirm that I correctly understand the problem? – csk Jul 17 at 18:06
  • @csk, yes this is the problem! – Mariosmsk Jul 17 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.