Hello,

Have you tried this following code? Using iface.mapCanvas().mapTool().pointsZM() is good for me with any digitizing tool, while drawing.


# Measurement object (adapt with crs/transform context/ellipsoid)
da = QgsDistanceArea()
da.setSourceCrs(QgsProject.instance().crs(), QgsProject.instance().transformContext())
# If distance measurement must use ellipsoid
da.setEllipsoid(QgsProject.instance().ellipsoid())

# This is a demonstration function to adapt with your needs
def showArea(current_point):
    if not isinstance(iface.mapCanvas().mapTool(), QgsMapToolDigitizeFeature):
        return

    # Snapping
    snapped_point = iface.mapCanvas().snappingUtils().snapToMap(current_point).point()
    if not snapped_point.isEmpty():
        current_point = snapped_point

    # Coordinates of currently drawn points in map coordinates
    points = [QgsPointXY(point) for point in iface.mapCanvas().mapTool().pointsZM()]
    points.append(current_point)

    # Get area
    print(da.measurePolygon(points))

# Must be handled correctly in the final code, but here is for testing
iface.mapCanvas().xyCoordinates.connect(showArea)



Le 29/04/2023 à 01:45, Catania, Luke A ERDC-RDE-GRL-VA CIV via QGIS-Developer a écrit :

When you digitize a shape using the Edit menu in QGIS is the shape accessible?  I am looking to get he area of the shape as it is drawn.  I have added an event filter to my code to capture the coordinates and calculate it by creating a QgsGeometry, but my code is getting complicated as there are many shapes that a user can draw from this menu so if I can get access to this shape if it is temporary in memory, then I can just calculate the area on the shape and not have to capture all the positions of the mouse when clicked and moved.


_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info:https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-developer

--
Jacky Volpes

Ingénieur SIG - Oslandia
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to