I have a feature class of adjacent polygons and I want to assign an integer attribute value to my polygons based on the following rules :

  • a polygon must not have the same attribute value than any of its neighbours
  • the number of attribute values must be as small as possible (I don't want to use the FIDs, because I want to convert my polygons to an 8-bit raster, so I can use no more than 256 values)

Here is a small example :

enter image description here

I am planning to loop on all features, look for neighbours, and assign the smallest possible value, but maybe there is a more efficient algorithm or an existing tool. QGIS and ArcGIS 10.1 solutions are both welcome.