7

I've got a dataset of buildings roof segments in shapefiles. I need to sequentially number the roof segments from 1 to n of each building.

Is there a way to do it with the QGIS field calculator?

Actual:

enter image description here

Expected:

enter image description here

It's pretty similar to an ArcPy question: Auto increment by group in ArcGIS ModelBuilder

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Guts
  • 612
  • 1
  • 6
  • 12
  • Another answer a little bit faster : https://gis.stackexchange.com/questions/433973/auto-increment-associated-with-field-type-in-qgis – Maxime Riou Nov 06 '22 at 10:16

1 Answers1

13

You can use this expression:

array_find(array_agg("BUILDING"||'_'||-$id,"BUILDING"),"BUILDING"||'_'||-$id)+1

Result:

enter image description here

MrXsquared
  • 34,292
  • 21
  • 67
  • 117