I've got a dataset of tiles with individual attributes (NAME,date,sensor). All tiles have the same size. After dissolving layer, in some locations tiles with the same NAME attribute overlap each other but have different sensor and date I need to merge geometry of tiles and concatenate sensor and date attribute separated with sign "/". Is there any way to do it with the QGIS field calculator and "Join attributes by location"? I have tried use "Join attributes by location" but as an output still I get overlapping shapes.
1 Answer
Use the (criminally underused) 'Aggregate' tool in the Processing Toolbox.
Group by name
; set first_value
as the aggregate function for the name
field, and concatenate_unique
for the other two fields, using /
as the delimiter (if that's how you want it).
Sample data - note two distinct name values, 111
and 123
Processing options:
Result:
The tool will concatenate attributes based on the order of your features in your source file.
If you want the concatenated values to be in a specific order regardless of source file feature order, then you may need to either (a) use Virtual Layer to set the order of your features before concatenating, or (b) post-process the aggregated data using an expression like below in Field Calculator (may be cumbersome if you have lots of fields or need to run the aggregation multiple times).
For example to make sure the aggregated sensor field shows sensor1/sensor2
instead of sensor2/sensor1
, use the expression below in Field Calculator on the aggregated layer:
array_to_string(array_sort(string_to_array("sensor",'/')),'/')
-
2
-
1Haha, thanks. I've had to take a break after spending a bit too much time here instead of doing my actual job... Oct 4, 2021 at 10:54
-
-
-
1If the answer has helped you don't forget to mark it as accepted so that others will find it easier to get to this solution. Oct 5, 2021 at 6:21