Assuming the topology is perfect, creating a field 'WKT' with the the expression
geom_to_wkt( $geometry)
in your point layer, you could use the expression:
min( attribute( get_feature('points','WKT', geom_to_wkt(start_point($geometry) )),'year'),attribute( get_feature('points','WKT', geom_to_wkt(end_point($geometry) )),'year'))||'-'|| max( attribute( get_feature('points','WKT', geom_to_wkt(start_point($geometry) )),'year'),attribute( get_feature('points','WKT', geom_to_wkt(end_point($geometry) )),'year'))
in the field calculator of the pipe layer, creating a text string.
- attribute(feature, attribute_name) Returns the value of a specified
attribute from a feature, here, the year of the point feature
obtained.
- get_feature(layer, attribute, value) returns the first feature of a layer matching a given attribute value. Here we check if we
can find a point with the same coordinates (in WKT format) as the
ones of your line's start and end vertices.
- start_point(geometry) returns the first node from a geometry. Here the first vertex of your line.
- end_point(geometry) returns the last node from a geometry. Here the last vertex of your line.
- geom_to_wkt(geometry) returns the Well-Known Text (WKT)
representation of the geometry.
You could even update it to:
CASE
WHEN attribute( get_feature('points','WKT', geom_to_wkt(start_point($geometry) )),'year') = attribute( get_feature('points','WKT', geom_to_wkt(end_point($geometry) )),'year')
THEN attribute( get_feature('points','WKT', geom_to_wkt(end_point($geometry) )),'year')
ELSE min( attribute( get_feature('points','WKT', geom_to_wkt(start_point($geometry) )),'year'),attribute( get_feature('points','WKT', geom_to_wkt(end_point($geometry) )),'year'))||'-'|| max( attribute( get_feature('points','WKT', geom_to_wkt(start_point($geometry) )),'year'),attribute( get_feature('points','WKT', geom_to_wkt(end_point($geometry) )),'year'))
END
in order to show just one year if two points with the same year are connected (getting 200X instead of 200X-200X).
The main advantage of this method is that if your data changes in your points, you can update it very fast with just one field calculator.
You could even add this rule as an Autofield for when you create new lines.