2

In QGIS 3.16.0 I have a postgis-polygon-layer with a field "array_polygon" which contains an array.

When digitizing a postgis-point-layer-point I would like to use the different array-values of the intersecting polygon in different fields as a default value to avoid lots of spatial queryies (one for every field).

The polygon layer has an "array_polygon"-field with type "QVariantList" and type name "_float8" and length "-1" and precision "0". The point layer has an "polygon_info"-fiel with type "QVariantList" and type name "_float8" and length "-1" and precision "0" too.

The "polygon_info"- field of the point-layer has a default value like

array_get(aggregate(
layer:= 'my_polygon_layer',
aggregate:='array_agg',
expression:=array_polygon,
filter:=intersects($geometry, geometry(@parent))),0)

The preview shows array-values as expected:

But the "polygon-info"-field in my point-layer stays empty after digitizing a point over a polygon: enter image description here

(I tried the expression without "array_get("...",0) too but without success).

My other fields - which should refer to "polygon_info"-array have a default value like

array_get( "polygon_info" ,0) 

(I checked

array_get( current_value("polygon_info") ,0) 

too) but every approach has a NULL-result too.

What is wrong?

  1. Has the expression or field-definition to be different to store the evaluated array (as seen in preview) in my point-attribute-table ?
  2. Is the spatial-query not carried out before the default-values are set - how can I force QGIS to make the spatial query first and after that extracting the values from this field?
  3. Or is my expression wrong - which alternative is correct ?
6
  • Does array_to_string() on a string field work? If so, its clearly a datatype issue.
    – MrXsquared
    Jan 19, 2021 at 17:48
  • As you already use QGIS 3.16, you could try using the new overlay_intersects expression. Something like (pseudo expression) if ( overly_intersescts, your_expression, empty). And, as mentioned by @MrXsquared, try converting the output to a string and create a string field for testing
    – Babel
    Jan 19, 2021 at 22:42
  • also for testing, maybe get the first element in the array and write to string, or similar.
    – nr_aus
    Jan 20, 2021 at 2:54
  • @nr_aus: the expression already gets the first element in the array, see it's basic structure: array_get(array,0) - 0 for first element.
    – Babel
    Jan 20, 2021 at 10:57
  • 1
    @babel, thanks for that - I saw that after I posted, forgot to correct it....... you guys are saying what im thinking anyways.... maybe also try some of the other array_ methods... array_first also seems a bit more suitable in this instance. array_find method may also prove helpful with debug.
    – nr_aus
    Jan 20, 2021 at 14:05

1 Answer 1

2

For debugging reasons I made a new fresh project with just this two layers directly from database by browser (and afterwards by inserting the point-layer as QLR-file too). Both point-layer-arrays now worked in the new project as aimed/expected.

In my old project I inserted the QLR from the "old" layer. But the "old" layer and the inserted layer from QLR still didn't work. Then I inserted the point layer via browser from postgresql-database and copied the code from the "old"-layer as default-value to the new point-layer. Surprisingly the attribute-field was filled now in the new layer of the "old" project.

So maybe there is a bug in my project/layer-definition (there are several spatial queries / default values / constraints / value relations in this layer and relations to other child-layers).

I'll try to narrow down the reason. But however - code and dataformat was not wrong. Maybe I can set up the layer newly with his settings without getting this problems again.

Your Answer

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

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