9 Jun 2022

QGIS 3: Symbology with Geometry Generator - Draw One Convex Hull For All Features With Same Attribute

I have a layer name "Trails" with an attribute "Trail ID", which contains uniquie, consecutive Feature/Trail IDs, and an attribute "Schwierigkeit" (trail difficulty). For all features with the value "black" for the attribute "Schwierigkeit" I want to render one convex hull. The below code will select the last element in of all the features in the layer and apply the code for drawing the polygon only once. The first
array_foreach()
in the code will create an array of all features (series generated from 1 to feature count number), over this array, the second array_foreach() will apply the geometry finction on each element which meets the condition of the
array_filter()
function. The
collect_geometries()
function finally puts all those single geometries within the resulting array into one multiline geometry, for which I then draw the hull.

if($id = maximum($id),
convex_hull(
collect_geometries(
with_variable('my_arr', 
array_foreach(
generate_series(1,  layer_property( 'trails', 'feature_count'), 1),
get_feature('trails', 'Trail ID', @element)
),
array_foreach(
array_filter(@my_arr, attribute(@element, 'Schwierigkeit')='black') , geometry(@element)))))
, NULL)

28 Feb 2022

QGIS 3: Geometry Generator Expression for Points at Line Intersections

A solution for symbolizing line intersections between the current layer's features and another layer's features ('Tracks Subset=Detail'). The
generate_series
is used with an
aggregate
which yields the number if features in the other layer used for the intersection. The
array_foreach
iterates over all features of the other layer and intersects each line with the input layer's current feature. The
array_filter
is needed to filter out the epmty geometries that could result after the intersection. If you wouldn't do this, the code would break when calling
collect_geometries
, which is needed to finally convert the array of geometries into a valid, digestible geometry collection, fed into the geometry generator with checking Point/Multi-POint as geometry type..
with_variable ('my_series', generate_series(1, aggregate(layer:='Tracks Subset=Detail', aggregate:='max', expression:="id")),
	collect_geometries(
		array_filter(
		array_foreach(@my_series, if(is_empty_or_null( 
			intersection(geometry(get_feature('Tracks Subset=Detail', 'id', @element)),
			$geometry)), 'x', intersection(geometry(get_feature('Tracks Subset=Detail', 'id', @element)),
			$geometry))
			), 
		@element != 'x'
	)
  )
)

25 Nov 2020

QGIS3: Aggregate Data of Intersecting Features: Concatenate String Attributes of Polygons Crossed by Line Features

regexp_replace(aggregate(layer:='Prcl_Lyr', aggregate:='concatenate', expression:="Prp_Ownr",filter:=intersects( $geometry, geometry(@parent)), concatenator:='/'), '[/]{2,}', '/')
Polygon Layer "Parcell_Lyr" Field holding Owner Data "Prop_Ownr" The parent layer is the line layer with the lines, for which we want to collect the polygon data, intersected by the single line features. For aggregated NULL or empty strings the concatenator character would be replicated without strings inbetween - for this, the regex "[/]{2,}" which matches a forward slash, repeated twice or more, will replace those doubled slashes with a single one.