2

I am using ArcGIS Pro for this operation. I have a attributes for features which represent a value for a given year. A portion of the table is here:

enter image description here

As you can see, not every feature has a value for every attribute. These values are the percentage of workers in any given year employed in an industrial sector job. I would like to symbolize the features based on the most recent year. That would mean that ArcGIS would use the 2011 value for Aruba, null for Afghanistan, null for Angola, the 2015 value for Albania, etc.

Is there a way to accomplish this task?

4
  • You could create a new field and populate the latest value into that field and then symbolise on that
    – Midavalo
    May 8, 2017 at 2:54
  • Also please confirm you're using ArcGIS Pro 2.0, as per your tag? The beta has only just been released in the past week.
    – Midavalo
    May 8, 2017 at 2:55
  • Sorry, did not realize that pro 2 was a tag. What would be the process to populate with the latest value? Would I need to do that in the spreadsheet first and then join to the features in ArcGIS or can that be accomplished in ArcGIS?
    – SteveC
    May 8, 2017 at 3:28
  • Field calculator with a bit of If/elif/else would get everything into a single field
    – Midavalo
    May 8, 2017 at 3:29

1 Answer 1

1

Plug the following code into the Python window and it should do what you want.

You need to set the path to your FC and you'll need to put the list of all your possible fields that have values in the to fields variable. We then sort the list from highest to lowest (alternative you could remove the reverse and simply list them in high to low). You then need to add a field which you'll symbolize from: SymbolField. The cursor goes row by row and field by field. When it finds a value, it breaks the loop, uses that value and calcs SymbolField. You'll need to update row[3] to the index of whatever position your SymbolField becomes. In my example I had 3 fields, and SymbolField becomes the 4th (or the 3rd in a zero index situation)

fc = r"c:\path\to\your\featureclass"
fields = sorted(["IND2010", "IND2011", "IND2012"], reverse=True)
arcpy.AddField_management(fc, "SymbolField", "FLOAT")

with arcpy.da.UpdateCursor(fc, fields + ["SymbolField"]) as cursor:
    for row in cursor:
        for index, f in enumerate(fields):
            if row[index]:
                print("Found value in {} of {}".format(f, row[index]))                
                row[3] = row[index]
                break
        cursor.updateRow(row)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.