I'm using QGIS 3.4.7. I have one vector layer with road lines and a second with city polygons (and a third with city centroid points if that is better). I have already used symbologies with arrows to confirm the road directions match the direction of traffic in real life. My plan is to color the roads based on whether their traffic flows either into or out of the city, so I was wanting to use something like this in the field calculator after selecting my target city from either the polygon or point version of the city layer:
CASE
WHEN distance(end_point($geometry), targetcity) - distance(start_point($geometry), targetcity) > 0 THEN 'out'
WHEN distance(end_point($geometry), targetcity) - distance(start_point($geometry), targetcity) < 0 THEN 'in'
WHEN distance(end_point($geometry), targetcity) - distance(start_point($geometry), targetcity) == 0 THEN 'no_flow'
END
However, I haven't figured out how to use the field calculator while referencing another layer. I would ideally like a solution without a lot of Python coding because I'm fairly new to QGIS but I will learn it if I have to.
get_feature()
function returns the first feature of a layer matching a given attribute value. I don't think you can use it withis_selected()
.aggregate
function?