[Qgis-user] Expression to read field value from composer layout?
Patrick Dunford
enzedrailmaps at gmail.com
Wed Aug 4 05:06:16 PDT 2021
OK
Is it then possible I might have to write my own function to get the
values from the Qgis API?
I already have a Python script that runs in the main window console that
contains this code
layoutTitle = "Landscape 16:9 Header Nav Copyright Filename 2021"
project = QgsProject.instance()
projectLayoutManager = project.layoutManager()
layout = projectLayoutManager.layoutByName(layoutTitle)
fileNameLabel = layout.itemById('Filename')
fileNameText = fileNameLabel.text()
How would I adapt that to a custom function in the Function Editor and
assuming it is for the current layout.
Thanks
On 4/08/21 11:44 pm, Stefan Giese (WhereGroup) wrote:
>
> Hi Patrick,
>
> I think that you can not get the text from the label with the
> item_variables function. The keys are limited to the predefinded
> variables like:
>
> _project_transform_context,item_id,item_uuid,layer_ids,layers,layout_dpi,layout_name,layout_numpages,layout_page,layout_pageheight,layout_pageoffsets,layout_pagewidth,miles_km,project_abstract,project_area_units,project_author,project_basename,project_creation_date,project_crs,project_crs_acronym,project_crs_definition,project_crs_description,project_crs_ellipsoid,project_crs_proj4,project_crs_wkt,project_distance_units,project_ellipsoid,project_filename,project_folder,project_home,project_identifier,project_keywords,project_last_saved,project_path,project_title,project_units,qgis_locale,qgis_os_name,qgis_platform,qgis_release_name,qgis_short_version,qgis_version,qgis_version_no,test,user_account_name,user_full_name
>
> But you can use your own variable like filename and access it from
> anywhere:
>
>
>
> Am 04.08.2021 um 13:27 schrieb Patrick Dunford:
>>
>> I'm looking through the documentation and there is this example:
>>
>>
>> 14.2.2.13. Layout Functions
>> <https://docs.qgis.org/3.10/en/docs/user_manual/working_with_vector/expression.html#id24>
>>
>> This group contains functions to manipulate print layout items
>> properties.
>>
>> Function
>>
>>
>>
>> Description
>>
>> item_variables
>>
>>
>>
>> Returns a map of variables from a layout item inside this print layout
>>
>> *An example:*
>>
>> *
>>
>> Get the scale of the ‘Map 0’ in the current print layout:
>>
>> map_get( item_variables('Map 0'), 'map_scale')
>>
>>
>> How do I find out how to get the text value of the layout item
>> "Filename" on the current print layout?
>>
>>
>> On 4/08/21 2:40 pm, Patrick Dunford wrote:
>>> It is just an ordinary text field on a composer layout I think. I
>>> don't use the atlas functionality.
>>>
>>> On 4/08/21 10:19 am, Nyall Dawson wrote:
>>>> On Wed, 4 Aug 2021 at 06:17, Patrick Dunford
>>>> <enzedrailmaps at gmail.com> wrote:
>>>>> Good day
>>>>>
>>>>> I am wishing to create a value in a field on a composer layout that
>>>>> reads the value of another field on the layout and calculates a
>>>>> value to
>>>>> be displayed.
>>>>>
>>>>> For example, I have an existing field called Filename on the
>>>>> layout and
>>>>> in a python script running in the main window console, I have this
>>>>> code
>>>>> that reads the value of the Filename field as follows:
>>>>>
>>>>> layoutTitle = "Landscape 16:9 Header Nav Copyright Filename 2021"
>>>>>
>>>>> project = QgsProject.instance()
>>>>> projectLayoutManager = project.layoutManager()
>>>>> layout = projectLayoutManager.layoutByName(layoutTitle)
>>>>>
>>>>> fileNameLabel = layout.itemById('Filename')
>>>>> fileNameText = fileNameLabel.text()
>>>>>
>>>>>
>>>>> Obviously I am hoping that doing this from a field within the layout
>>>>> that reads another field on the same layout will be much simpler than
>>>>> the above. How exactly would I achieve that?
>>>> Just to clarify -- by "field" do you mean "a field value from the
>>>> atlas layer", or "a text label item"?
>>>>
>>>> Nyall
>>
>> _______________________________________________
>> Qgis-user mailing list
>> Qgis-user at lists.osgeo.org
>> List info:https://lists.osgeo.org/mailman/listinfo/qgis-user
>> Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-user
> --
> Mit freundlichen Grüßen
> Stefan Giese
> Projektleiter/Consultant
> ************************************************************
> Aufbau von Geodateninfrastrukturen mit Open-Source-Software
> FOSS Academy 5 Tage-Kompaktkurs „Sommerschule 2021“
> Jetzt anmelden:https://foss-academy.com/kompaktkurse/
> *************************************************************
> WhereGroup GmbH
> Schwimmbadstr. 2
> 79100 Freiburg
> Germany
>
> Fon: +49 (0)761 / 519 102 - 61
> Fax: +49 (0)761 / 519 102 - 11
>
> stefan.giese at wheregroup.com
> www.wheregroup.com
> Geschäftsführer:
> Olaf Knopp, Peter Stamm
> Amtsgericht Bonn, HRB 9885
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210805/7a59a17f/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ljjnehpmbiioiaaj.png
Type: image/png
Size: 47504 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210805/7a59a17f/attachment-0001.png>
More information about the Qgis-user
mailing list