3

I want to run an aggregate expression in field calculator based on the mid point of a line.

The following uses a buffer of the line but I need it to be on midpoint -how do I do this?

aggregate(layer:='Roads_DVR_July2019', aggregate:='max', expression:="Road_Name"+'\\'+"Photo_Name",filter:= intersects(buffer($geometry,5,4), geometry(@parent)))

There are some options in this post but I am hoping that there is a way to do this without creating a new file with the mid points. For the start/end we have xat(0) (start point), xat(-1) (end point). Is there something for mid point?

UPDATE 1

If I use the following I get no results or error.

aggregate(layer:='Roads_DVR_July2019', aggregate:='max', expression:="Road_Name"+'\\'+"Photo_Name",filter:= intersects(buffer(line_interpolate_point($geometry, $length/2),5,4), geometry(@parent)))

enter image description here

Zoomed into the center we see there is at least one point of the point dataset that is within 5m of the midpoint of the line.

enter image description hereI have tried with 5,50 and 500m buffer but get no results so there must be something wrong with the filter. Is the point it buffers the centroid mid point rather than the mid point on the line that is

ogr2ogr OUTPUT.gpkg "Roads.tab" -dialect sqlite -sql "SELECT ST_Line_Interpolate_Point(geometry, 0.5) AS geometry,* FROM \"Roads\"" -f "GPKG"
GeorgeC
  • 8,228
  • 7
  • 52
  • 136

1 Answers1

3

Try this one for the filter:

filter:= intersects(buffer(line_interpolate_point($geometry, $length/2),5,4), geometry(@parent))

it will take the point at 50% of the line length for the buffer

eurojam
  • 10,762
  • 1
  • 13
  • 27
  • thanks but i get no result with this. I've added a screengrab showing what it should be doing. – GeorgeC Dec 07 '20 at 04:26
  • 1
    It seems like your layer 'Roads_DVR_July2019' is a point layer, so the filter will not work because it expects a line layer for the function line_interpolate_point. – eurojam Dec 07 '20 at 06:43
  • Yes 'Roads_DVR_July2019' is a point layer, the layer it is finding the midpoint of and the buffering is a line layer 'DSC_Roads'. This calculation is run on the field calc of the line layer, so you don't see it's name. So basically it should be looking for the midpoint of the line layer, buffering it by 5m and then checking which point of the 'Roads_DVR...' point layer is within/intersects the buffer to take the 'Road_Name' etc attribution from. The reason for it not to use the start/end point is that sometimes the system gets the value of connecting streets. – GeorgeC Dec 07 '20 at 23:09
  • as above the layer it's working on is a line layer. – GeorgeC Dec 08 '20 at 22:26