[QGIS-Developer] Reading current measurement with python

Jacky Volpes jacky.volpes at oslandia.com
Fri Oct 6 06:00:09 PDT 2023


Hi Simon,

Ok, I understand your question now.

Unfortunately, the measurement tool is not accessible with the python API.

As I don't have the context explaining why you need this, I can propose 
you to find another way for your process, or, if you really need to get 
the measurement value, here is a code snippet that finds the text within 
the measurement dialog (I don't recommend you to use this in a 
production environment though, or you might have unexpected behaviors if 
something changes in the dialog implementation).


measurementDialogs = [d for d in 
iface.mainWindow().findChildren(QDialog, "QgsMeasureBase") if d.isVisible()]
if len(measurementDialogs) == 1:
     measurementDialog = measurementDialogs[0]
     totalTextLineEdit = measurementDialog.findChild(QLineEdit, "editTotal")
     if totalTextLineEdit is not None:
         print(totalTextLineEdit.text())


Best regards,

Jacky Volpes

Ingénieur SIG - Oslandia

--

Le 04/10/2023 à 10:15, Simon Gröchenig a écrit :
> Hi Jacky,
>
> thanks for your help and for pointing me to this code snippet.
>
> However, I see that the measurement tools are instances of QgsMapTool with an QAction (and not QgsMapToolDigitizeFeature) and therefore mapTool().pointsZM() is not available.
>
> Now I wonder if I can utilize the QgsRubberBand
>
> Best regards
> Simon
>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 2 Oct 2023 08:56:58 +0200
> From: Jacky Volpes <jacky.volpes at oslandia.com>
> To: qgis-developer at lists.osgeo.org
> Subject: Re: [QGIS-Developer] Reading current measurement with python
> Message-ID: <352a9e94-9010-4f39-8738-89323a87a15a at oslandia.com>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
> Hi,
>
> You can have a look at this snippet:
> https://lists.osgeo.org/pipermail/qgis-developer/2023-May/065789.html
>
> Regards,
>
> --
>
> Jacky Volpes
>
> Ing?nieur SIG - Oslandia
>
> --
>
> Le 02/10/2023 ? 07:05, Simon Gr?chenig via QGIS-Developer a ?crit?:
>> Hi list,
>>
>> is it possible to get the current line/area measurement with Python?
>>
>> Simon
>>
>>
>> _______________________________________________
>> 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
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231002/ce6f1c41/attachment-0001.htm>
>


More information about the QGIS-Developer mailing list