Hello
I have a layer that has approximately 50 indivdual polygons that I need to show colored on a map. I do not want to have 50 different colors as it is impossible to relate that many. I would like to only use 5-10 colors and ArcMap not place any 2 colors side by side?
I think I have done this in the past but cannot remember the steps.
Thanks
Tina
The first thing that came to mind is creating a new field and inserting a value of 5-10, however many colors you wanted to use. You would have to make sure no adjacent polygons would have the same value. This way you could symbolize each value differently.
I'm not sure if ArcMap has a way to automatically do this.
Steven
That is too bad there is no "Four Color" script working for 10+. It looks like that would have solved your issue.
Kim, you can symbolize any distribution of polygons with a four color map such that no two colors touch. below is some code that will create a new attribute called fourcolor. You can symbolized off of the resulting values. You will have the change the path to the inFC dataset to point to your data.
See here for more information....ESRI Mapping Centre - Maps: Los Angeles Ethnicity
Here is an ESRI four-color tool but I do not know if it will work with your version of ArcGIS
Esri Mapping Centre - ArcGIS Resources
Good luck.
try:
print"Minimum Color Map"
print "Copyright 2011, Gerry Gabrisch\n"
import arcpy, os, sys, string, traceback, operator
inFC = r"On-Reservation Clam Harvest Areas"
print "Creating a minimum color map for "+ inFC
print "Adding field 'FourColor...'"
listoffields = []
for field in arcpy.ListFields(inFC):
listoffields.append(field.name)
if 'GerryTemp' not in listoffields:
arcpy.AddField_management(inFC, "GerryTemp", "SHORT")
if 'FourColor' not in listoffields:
arcpy.AddField_management(inFC, "FourColor", "SHORT")
del listoffields
counter = 0
rows = arcpy.UpdateCursor(inFC)
for row in rows:
row.GerryTemp = counter
rows.updateRow(row)
counter +=1
listofconnections = []
g1 = arcpy.Geometry()
geometrylist1 = arcpy.CopyFeatures_management(inFC, g1)
g2 = arcpy.Geometry()
geometrylist2 = arcpy.CopyFeatures_management(inFC, g2)
print "Sorting...Please wait..."
counter1 = 0
for geometry1 in geometrylist1:
connection = []
connection.append(counter1)
counter = 0
for geometry2 in geometrylist2:
#connection.append(counter)
if (geometry1.touches(geometry2) or geometry1.overlaps(geometry2)) and counter != counter1:
connection.append(counter)
counter +=1
counter1 += 1
listofconnections.append(connection)
#sort the list based on the elements (more lists) by length
listofconnections = sorted(listofconnections, key = len, reverse = True)
iscolor1 = [];iscolor2 = [];iscolor3 =[];iscolor4 = []
cantbecolor1 =[];cantbecolor2 =[];cantbecolor3 =[]; cantbecolor4 =[]
counter = 0
for item in listofconnections:
#Set the polygon with the largest number of neighbors to color #1
if counter == 0:
iscolor1.append(item[0])
counter2 = 0
for item2 in item:
if counter2 > 0:
cantbecolor1.append(item2)
counter2 += 1
#For any disconnected polygons, give them a value of 4
elif len(item) == 1:
iscolor4.append(item[0])
counter2 = 0
for item2 in item:
if counter2 > 0:
cantbecolor4.append(item2)
counter2 += 1
#For any remaining polygons, sort out the colors...
else:
if item[0] not in cantbecolor1:
iscolor1.append(item[0])
counter2 = 0
for item2 in item:
if counter2 > 0:
cantbecolor1.append(item2)
counter2 += 1
elif item[0] not in cantbecolor2:
iscolor2.append(item[0])
counter2 = 0
for item2 in item:
if counter2 > 0:
cantbecolor2.append(item2)
counter2 += 1
elif item[0] not in cantbecolor3:
iscolor3.append(item[0])
counter2 = 0
for item2 in item:
if counter2 > 0:
cantbecolor3.append(item2)
counter2 += 1
else:
iscolor4.append(item[0])
counter2 = 0
for item2 in item:
if counter2 > 0:
cantbecolor4.append(item2)
counter2 += 1
counter += 1
print "Writing color codes to the attribute table..."
rows = arcpy.UpdateCursor(inFC)
for row in rows:
if row.GerryTemp in iscolor1:
row.FourColor = 1
if row.GerryTemp in iscolor2:
row.FourColor = 2
if row.GerryTemp in iscolor3:
row.FourColor = 3
if row.GerryTemp in iscolor4:
row.FourColor = 4
rows.updateRow(row)
arcpy.DeleteField_management(inFC, "GerryTemp")
print "All done."
except arcpy.ExecuteError:
msgs = arcpy.GetMessages(2)
arcpy.AddError(msgs)
print msgs
except:
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
print pymsg + "\n"
print msgs
Here is an ArcToolbox version of the script above that works in 10.1 and ought to work in any version of 10.1 or later.