[QGIS-Developer] Rotating selected features programmatically
Catania, Luke A ERDC-RDE-GRL-VA CIV
Luke.A.Catania at erdc.dren.mil
Thu Aug 1 11:29:59 PDT 2024
def rotateFeature(self):
"""Find the rotate feature action in QGIS toolbar and trigger it so the user can rotate the element.
"""
# We want to detect when the rotation is complete with a geometryChanged signal so we can commit the changes and
# end the edit session.
self.vector_layer.editBuffer().geometryChanged.connect(self.element_layer_rotated)
# Get all actions so we can search for the mActionRotateFeature action.
actions = iface.mainWindow().findChildren(QAction)
action = [x for x in actions if x.objectName()=='mActionRotateFeature'][0]
expression = '"Element_Nb" = '
expression = expression + "\'" + f'{self.element_number}' + "\'"
QgsMessageLog.logMessage(f"expression: {expression}", "StandoffLayers", Qgis.Info)
processing.run("qgis:selectbyexpression",
{'INPUT':self.vector_layer,
'EXPRESSION': expression,
'METHOD':0
}
)
# Inititates rotate feature action allowing to select a snap to value.
action.trigger()
QgsMessageLog.logMessage(f"Rotate Feature Action Triggered", "ElementPlacementTool", Qgis.Info)
def element_layer_rotated(self):
"""When the rotate action is triggered it seems to ignore the ElementPlacementTool events, so in order to end the edit session
we need to detect a geometryChanged event after the rotation is complete.
"""
QgsMessageLog.logMessage(f"Element Layer Rotated: {self.vector_layer.name()}", "ElementPlacementTool", Qgis.Info)
# Disconnect from the signal so we can just commit the changes.
self.vector_layer.editBuffer().geometryChanged.disconnect()
# Save changes and end edit mode
self.vector_layer.commitChanges()
self.vector_layer.endEditCommand()
self.deactivate()
From: Jacky Volpes <jacky.volpes at oslandia.com>
Sent: Thursday, August 1, 2024 8:26 AM
To: Catania, Luke A ERDC-RDE-GRL-VA CIV <Luke.A.Catania at erdc.dren.mil>; 'qgis-developer' <qgis-developer at lists.osgeo.org>
Subject: Re: [QGIS-Developer] Rotating selected features programmatically
Hi Luke,
Please provide a PyQGIS code snippet to reproduce. It will be more convenient to comment and suggest modifications.
Thanks,
--
Jacky Volpes
Ingénieur développeur SIG - Oslandia
Le 26/07/2024 à 22:06, Catania, Luke A ERDC-RDE-GRL-VA CIV via QGIS-Developer a écrit :
I am using the select by expression tool through python to select my features and then I trigger rotation through python I see both selected features rotating, but when I click to end the rotation, it only rotated one of the features and left the other one as is. If I do this through the QGIS using the selection by expression in the selection toolbar and the rotate in the advanced digitizing tool bar rotating both features works fine.
Any Ideas?
Luke
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer at lists.osgeo.org<mailto:QGIS-Developer at lists.osgeo.org>
List info: Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked
Unsubscribe: Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20240801/45b553b6/attachment-0001.htm>
More information about the QGIS-Developer
mailing list