Skip to main content
deleted 1 character in body
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 188

Try this python script:

layer = iface.activeLayer() #Click layer in layer tree
idfield = 'enum' #Change to match the name of your field'field

coords = [[f.geometry().asPoint().x(), f.geometry().asPoint().y(), f.id()] for f in layer.getFeatures()] #List x coordinate, y coordinate and id of each point
coords.sort(key=lambda k: (k[1],-k[0]), reverse=True) #Sort by y, x
order = [i[2] for i in coords] #Extract only the ids from the sorted list of lists

i = layer.fields().indexFromName(idfield)
attrMap = {id: {i:e} for e,id in enumerate(order,1)}
layer.dataProvider().changeAttributeValues(attrMap)

enter image description here

Try this python script:

layer = iface.activeLayer() #Click layer in layer tree
idfield = 'enum' #Change to match the name of your field'

coords = [[f.geometry().asPoint().x(), f.geometry().asPoint().y(), f.id()] for f in layer.getFeatures()] #List x coordinate, y coordinate and id of each point
coords.sort(key=lambda k: (k[1],-k[0]), reverse=True) #Sort by y, x
order = [i[2] for i in coords] #Extract only the ids from the sorted list of lists

i = layer.fields().indexFromName(idfield)
attrMap = {id: {i:e} for e,id in enumerate(order,1)}
layer.dataProvider().changeAttributeValues(attrMap)

enter image description here

Try this python script:

layer = iface.activeLayer() #Click layer in layer tree
idfield = 'enum' #Change to match the name of your field

coords = [[f.geometry().asPoint().x(), f.geometry().asPoint().y(), f.id()] for f in layer.getFeatures()] #List x coordinate, y coordinate and id of each point
coords.sort(key=lambda k: (k[1],-k[0]), reverse=True) #Sort by y, x
order = [i[2] for i in coords] #Extract only the ids from the sorted list of lists

i = layer.fields().indexFromName(idfield)
attrMap = {id: {i:e} for e,id in enumerate(order,1)}
layer.dataProvider().changeAttributeValues(attrMap)

enter image description here

Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 188

Try this python script:

layer = iface.activeLayer() #Click layer in layer tree
idfield = 'enum' #Change to match the name of your field'

coords = [[f.geometry().asPoint().x(), f.geometry().asPoint().y(), f.id()] for f in layer.getFeatures()] #List x coordinate, y coordinate and id of each point
coords.sort(key=lambda k: (k[1],-k[0]), reverse=True) #Sort by y, x
order = [i[2] for i in coords] #Extract only the ids from the sorted list of lists

i = layer.fields().indexFromName(idfield)
attrMap = {id: {i:e} for e,id in enumerate(order,1)}
layer.dataProvider().changeAttributeValues(attrMap)

enter image description here