1

In QGIS (3.34.3) with an input form I'm assigning as the default value of a field of my buildings polygons the code (codice) from the polygon area to which it belongs, that is stored in another layer, using the following expression, and all is working well. When I export the project to be used with QField (3.1.9) for on-site activities, the default value remains blank. The expression is:

attribute(
  get_feature_by_id(
    'aree',
    map_get(overlay_intersects(
     layer:='aree',
     expression:= $geometry, return_details:=true, limit:=1)[0], 'id')
    ),
'codice') 

Does QField support this kind of expressions in default values?

1 Answer 1

3

I didn't have any trouble getting your exact expression to work in a dummy project, using QGIS 3.34.3 and QField 3.1.9 on Android with project exported using USB cable. (see video here)

  • When you say it's "working well" in QGIS is it just the expression preview or is it being saved into the layer? Any chance you accidentally created your data field using the wrong type?

  • Did your aree layer get renamed during the export process? Look at the list of layer names in QField to check.


As an aside, your expression seems almost impressively convoluted - if you wanted to just get the codice attribute from an intersecting polygon on the aree layer you could simply use

overlay_intersects('aree',
                   "codice")[0]

You could even throw in the parameter sort_by_intersection_size:='des' so the first result will be from the feature with the largest overlap.

2
  • Well I see we're using the same software versions, but I am not still able to get this result. About the first point, the value populates the field and is saved into the layer. About the second point the layer is not renamed. Also your simplification is very interesting. One thing that I didn't specify is that the layers are in a PostGIS database, and are exported with QFieldSync plugin for offline work. I'll try with simple file layers and report.
    – stefan0n
    Commented Mar 1 at 15:09
  • @stefan0n I don't know about now but in the past there used to be issues with QFieldSync offline exports and expressions that referred to layer names, because the plugin would add an "(offline)" to the layer names and so these expressions would stop working. That's why I was wondering if that still happened. Definitely try with simple file layers and see if that changes anything
    – she_weeds
    Commented Mar 1 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.