UPDATE 2 For some reason it's only updating roads that have one section and not multiple and also where there more than one point within the buffer it's not putting in any value. I have cleaned up the code to try and see why it's not functioning as expected...
def Check_Intersection (c_sel, l, start_end): #Find points within start/end of line
geom = l.geometry().asPolyline()
g = QgsGeometry.fromPointXY(geom[start_end])
buffer = g.buffer(10,4) #10m buffer with 4 segments
#buffer_to_iface(buffer) #add buffer to map for testing
for c in c_sel: # for each chainage point -ideally should be envelope in buffer area only
#print (c['RoadMntnc'],c['distance']) #show value for testing
if c.geometry().within(buffer):
print(l.id(),c['RoadMntnc'],int(c['distance']))
#Update record
# layer.startEditing()
# ntext=int(c['distance'])
# fieldName='Start_Chainage2'
# FieldIndex = l.fields().indexFromName(fieldName)
# layer.changeAttributeValue(l.id(), FieldIndex, ntext)
# layer.commitChanges()
break
def buffer_to_iface(buffer): #buffer to iface for testing
buff_layer = QgsVectorLayer('Polygon', 'buffer' , 'memory')
prov = buff_layer.dataProvider()
feat = QgsFeature()
feat.setGeometry(buffer)
prov.addFeatures([feat])
buff_layer.updateExtents()
QgsProject.instance().addMapLayers([buff_layer])[0]
roadlist=[]
layer = QgsProject.instance().mapLayersByName('DSC_Roads')[0]
chainage_layer= QgsProject.instance().mapLayersByName('DSC_Roads_10m_Chainage')[0]
for feature in layer.getFeatures(): # Create list of unique roads to work through
if feature['RoadMntnc'] not in roadlist:
roadlist.append(feature['RoadMntnc'])
#
#roadlist=['Kingston_Rd'] #for testing
#-----------------------------------------------------------------------
for road in roadlist: # for each road select line and point features
request = QgsFeatureRequest(QgsExpression('"RoadMntnc"= \'{0}\''.format(road)))
l_sel = layer.getFeatures(request)
c_sel = chainage_layer.getFeatures(request)
for l in l_sel: # repeat for each road segment
print (str(l.id())+l['RoadMntnc'])
start_end=0 #get start points
Check_Intersection (c_sel,l,start_end)
print ('Completed')
layer.updateFields()