[QGIS-Developer] Calculate area/perimtere/length of polygon/line while editing (Sylvain Th?ry)
Philipe Borba
philipeborba at gmail.com
Tue Mar 11 11:02:29 PDT 2025
In the Brazilian Army plugin, we have a tool to calculate the line length or the polygon area upon digitalization, like shown in the gif below:

The code used in this tool is available at: https://github.com/dsgoficial/DsgTools/blob/master/DsgTools/gui/ProductionTools/MapTools/MeasureTool/measureTool.py
> On 11 Mar 2025, at 13:37, qgis-developer-request at lists.osgeo.org wrote:
>
> Send QGIS-Developer mailing list submissions to
> qgis-developer at lists.osgeo.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://lists.osgeo.org/mailman/listinfo/qgis-developer
> or, via email, send a message with subject or body 'help' to
> qgis-developer-request at lists.osgeo.org
>
> You can reach the person managing the list at
> qgis-developer-owner at lists.osgeo.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of QGIS-Developer digest..."
>
>
> Today's Topics:
>
> 1. Re: Calculate area/perimtere/length of polygon/line while
> editing (Sylvain Th?ry)
> 2. Re: Calculate area/perimtere/length of polygon/line while
> editing (Catania, Luke A ERDC-RDE-GRL-VA CIV)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 11 Mar 2025 17:05:15 +0100
> From: Sylvain Th?ry <sylvain.thery at cnrs.fr>
> To: "Catania, Luke A ERDC-RDE-GRL-VA CIV"
> <Luke.A.Catania at erdc.dren.mil>, DelazJ <delazj at gmail.com>
> Cc: "qgis-developer at lists.osgeo.org" <qgis-developer at lists.osgeo.org>
> Subject: Re: [QGIS-Developer] Calculate area/perimtere/length of
> polygon/line while editing
> Message-ID: <a9f6f86d-4d22-4a2f-97c6-fa7e89e4b03b at cnrs.fr>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
> Hello,
>
> It seems there is a fix here :
> https://github.com/agiudiceandrea/calcarea2/blob/a6a3d7c5a98e64573731cd6a005da4e2d9836fdd/calcareaevent.py
>
> All the best,
> S.
>
>
> Le 11/03/2025 ? 16:14, Catania, Luke A ERDC-RDE-GRL-VA CIV via
> QGIS-Developer a ?crit?:
>>
>> Thanks. Plugin installed but will not run.? I get the error below. I
>> have QGIS 3.34.4.
>>
>> *TypeError: QgisInterface missing 'mActionDigitizeWithCurve' action *
>>
>> Traceback (most recent call last):
>> ? File "C:\PROGRA~1/QGIS33~1.4/apps/qgis-ltr/./python\qgis\utils.py",
>> line 423, in _startPlugin
>> ? ? plugins[packageName] = package.classFactory(iface)
>> ? File
>> "C:\Users/RDTECLAC/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\calcarea2\__init__.py",
>> line 29, in classFactory
>> ? ? return CalcAreaPlugin( iface )
>> ? File
>> "C:\Users/RDTECLAC/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\calcarea2\plugin.py",
>> line 66, in __init__
>> ? ? self.toolEvent = CalcAreaEvent( self.iface )
>> ? File
>> "C:\Users/RDTECLAC/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\calcarea2\calcareaevent.py",
>> line 478, in __init__
>> ? ? self.addFeatureEvent = AddFeatureEvent( iface )
>> ? File
>> "C:\Users/RDTECLAC/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\calcarea2\calcareaevent.py",
>> line 213, in __init__
>> ? ? self.geomPolygon = self.GeomPolygon( iface )
>> ? File
>> "C:\Users/RDTECLAC/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\calcarea2\calcareaevent.py",
>> line 316, in __init__
>> ? ? self.actionDigitizeWithCurve = getActionDigitizeWithCurve( iface )
>> ? File
>> "C:\Users/RDTECLAC/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\calcarea2\calcareaevent.py",
>> line 308, in getActionDigitizeWithCurve
>> ? ? raise TypeError(f"QgisInterface missing '{name}' action")
>> TypeError: QgisInterface missing 'mActionDigitizeWithCurve' action
>>
>> *From:*DelazJ <delazj at gmail.com>
>> *Sent:* Tuesday, March 11, 2025 11:08 AM
>> *To:* Catania, Luke A ERDC-RDE-GRL-VA CIV <Luke.A.Catania at erdc.dren.mil>
>> *Cc:* qgis-developer at lists.osgeo.org
>> *Subject:* Re: [QGIS-Developer] Calculate area/perimtere/length of
>> polygon/line while editing
>>
>> Hi,
>>
>> There is a CalcArea2 plugin whose description mentions it should be
>> doing that for polygons. You might want to take ispiration from their
>> code.
>>
>> Regards,
>>
>> Harrissou
>>
>> Le?mar. 11 mars 2025 ??15:55, Catania, Luke A ERDC-RDE-GRL-VA CIV via
>> QGIS-Developer <qgis-developer at lists.osgeo.org> a ?crit?:
>>
>> I need to calculate these values on the fly while I am in an edit
>> session resizing a polygon or a line.? I need the user to see this
>> calculation while they are editing not after the edits are
>> committed. I already have the UI set up to capture after commit,
>> but I need to capture while they are moving vertices and update
>> the values in the UI, so they don?t keep editing and then
>> committing just to see if they are close.? I want them to know
>> before they commit.
>>
>> Any idea how to achieve this?
>>
>> Luke Catania
>>
>> US Army ERDC-GRL
>>
>> JCMS Site Planning Developer
>>
>> _______________________________________________
>> QGIS-Developer mailing list
>> QGIS-Developer at lists.osgeo.org
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> <Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked>
>> Unsubscribe:
>> https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> <Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked>
>>
>>
>> _______________________________________________
>> QGIS-Developer mailing list
>> QGIS-Developer at lists.osgeo.org
>> List info:https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
> --
> Sylvain TH?RY - Ing?nieur d'?tudes CNRS en g?omatique
> UMR 5281 ART-Dev - Acteurs, Ressources et Territoires dans le D?veloppementhttps://art-dev.cnrs.fr/
> sylvain.thery at cnrs.fr - +33.4.11.75.70.98
> Universit? Paul-Val?ry Montpellier 3 - Site St Charles - Bureau 239
> @ postale : ART-Dev - St Charles - Route de Mende - 34 199 Montpellier Cedex 5
> https://www.researchgate.net/profile/Sylvain-Thery
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20250311/5ac92921/attachment-0001.htm>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: smime.p7s
> Type: application/pkcs7-signature
> Size: 4795 bytes
> Desc: Signature cryptographique S/MIME
> URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20250311/5ac92921/attachment-0001.bin>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 11 Mar 2025 16:37:45 +0000
> From: "Catania, Luke A ERDC-RDE-GRL-VA CIV"
> <Luke.A.Catania at erdc.dren.mil>
> To: Sylvain Th?ry <sylvain.thery at cnrs.fr>, DelazJ <delazj at gmail.com>
> Cc: "qgis-developer at lists.osgeo.org" <qgis-developer at lists.osgeo.org>
> Subject: Re: [QGIS-Developer] Calculate area/perimtere/length of
> polygon/line while editing
> Message-ID: <29d216cf35a34103ac67038c14846614 at erdc.dren.mil>
> Content-Type: text/plain; charset="utf-8"
>
> Thanks. That works. But looks like it only works when initially drawing the polygon as opposed to also working when editing an existing polygon. I have a similar tool to this that shows the area when drawing, just trying to figure out how to get it to work when editing an existing polygon. I was hoping to build on my own tool if there was an easy what to get a hold of some other signal that gets fired while editing.
>
>
>
> From: Sylvain Th?ry <sylvain.thery at cnrs.fr>
> Sent: Tuesday, March 11, 2025 12:05 PM
> To: Catania, Luke A ERDC-RDE-GRL-VA CIV <Luke.A.Catania at erdc.dren.mil>; DelazJ <delazj at gmail.com>
> Cc: qgis-developer at lists.osgeo.org
> Subject: Re: [QGIS-Developer] Calculate area/perimtere/length of polygon/line while editing
>
>
>
> Hello,
>
> It seems there is a fix here : https://github.com/agiudiceandrea/calcarea2/blob/a6a3d7c5a98e64573731cd6a005da4e2d9836fdd/calcareaevent.py <Blockedhttps://github.com/agiudiceandrea/calcarea2/blob/a6a3d7c5a98e64573731cd6a005da4e2d9836fdd/calcareaevent.pyBlocked>
>
> All the best,
> S.
>
>
>
> Le 11/03/2025 ? 16:14, Catania, Luke A ERDC-RDE-GRL-VA CIV via QGIS-Developer a ?crit :
>
> Thanks. Plugin installed but will not run. I get the error below. I have QGIS 3.34.4.
>
>
>
> TypeError: QgisInterface missing 'mActionDigitizeWithCurve' action
>
> Traceback (most recent call last):
> File "C:\PROGRA~1/QGIS33~1.4/apps/qgis-ltr/./python\qgis\utils.py", line 423, in _startPlugin
> plugins[packageName] = package.classFactory(iface)
> File "C:\Users/RDTECLAC/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\calcarea2\__init__.py", line 29, in classFactory
> return CalcAreaPlugin( iface )
> File "C:\Users/RDTECLAC/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\calcarea2\plugin.py", line 66, in __init__
> self.toolEvent = CalcAreaEvent( self.iface )
> File "C:\Users/RDTECLAC/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\calcarea2\calcareaevent.py", line 478, in __init__
> self.addFeatureEvent = AddFeatureEvent( iface )
> File "C:\Users/RDTECLAC/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\calcarea2\calcareaevent.py", line 213, in __init__
> self.geomPolygon = self.GeomPolygon( iface )
> File "C:\Users/RDTECLAC/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\calcarea2\calcareaevent.py", line 316, in __init__
> self.actionDigitizeWithCurve = getActionDigitizeWithCurve( iface )
> File "C:\Users/RDTECLAC/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\calcarea2\calcareaevent.py", line 308, in getActionDigitizeWithCurve
> raise TypeError(f"QgisInterface missing '{name}' action")
> TypeError: QgisInterface missing 'mActionDigitizeWithCurve' action
>
>
>
> From: DelazJ <mailto:delazj at gmail.com> <delazj at gmail.com>
> Sent: Tuesday, March 11, 2025 11:08 AM
> To: Catania, Luke A ERDC-RDE-GRL-VA CIV <mailto:Luke.A.Catania at erdc.dren.mil> <Luke.A.Catania at erdc.dren.mil>
> Cc: qgis-developer at lists.osgeo.org <mailto:qgis-developer at lists.osgeo.org>
> Subject: Re: [QGIS-Developer] Calculate area/perimtere/length of polygon/line while editing
>
>
>
> Hi,
>
> There is a CalcArea2 plugin whose description mentions it should be doing that for polygons. You might want to take ispiration from their code.
>
>
>
> Regards,
>
> Harrissou
>
>
>
> Le mar. 11 mars 2025 ? 15:55, Catania, Luke A ERDC-RDE-GRL-VA CIV via QGIS-Developer <qgis-developer at lists.osgeo.org <mailto:qgis-developer at lists.osgeo.org> > a ?crit :
>
> I need to calculate these values on the fly while I am in an edit session resizing a polygon or a line. I need the user to see this calculation while they are editing not after the edits are committed. I already have the UI set up to capture after commit, but I need to capture while they are moving vertices and update the values in the UI, so they don?t keep editing and then committing just to see if they are close. I want them to know before they commit.
>
>
>
> Any idea how to achieve this?
>
>
>
> Luke Catania
>
> US Army ERDC-GRL
>
> JCMS Site Planning Developer
>
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org <mailto:QGIS-Developer at lists.osgeo.org>
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer <Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked>
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer <Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked>
>
>
>
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org <mailto:QGIS-Developer at lists.osgeo.org>
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer <Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked>
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer <Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked>
>
> --
> Sylvain TH?RY - Ing?nieur d'?tudes CNRS en g?omatique
> UMR 5281 ART-Dev - Acteurs, Ressources et Territoires dans le D?veloppement https://art-dev.cnrs.fr/ <Blockedhttps://art-dev.cnrs.fr/Blocked>
> sylvain.thery at cnrs.fr <mailto:sylvain.thery at cnrs.fr> - +33.4.11.75.70.98
> Universit? Paul-Val?ry Montpellier 3 - Site St Charles - Bureau 239
> @ postale : ART-Dev - St Charles - Route de Mende - 34 199 Montpellier Cedex 5
> https://www.researchgate.net/profile/Sylvain-Thery <Blockedhttps://www.researchgate.net/profile/Sylvain-TheryBlocked>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20250311/5e33bb04/attachment.htm>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: smime.p7s
> Type: application/pkcs7-signature
> Size: 8254 bytes
> Desc: not available
> URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20250311/5e33bb04/attachment.bin>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>
> ------------------------------
>
> End of QGIS-Developer Digest, Vol 233, Issue 7
> **********************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20250311/0fee21bc/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Recording 2025-03-11 at 14.51.02.gif
Type: image/gif
Size: 3567132 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20250311/0fee21bc/attachment-0001.gif>
More information about the QGIS-Developer
mailing list