2

New to python here. I have looked through the 'similar questions' section to try and answer this myself and have found many attribute table python queries which are related to statistical operations. These typically call some other Arcgis tool. What I would like to do is a little different and I haven't found exactly how to do it yet.

I have two fields. The first has a list of name classifications for a cities general plan such as Lower Hillside, Residential Neighborhood, and so on. The second list houses a numerical 'code' which relates to conforming uses. Typically I have to select by attribute the specific general plan designation such as Lower Hillside and then use field calculator on the selected features to fill the second attribute table with the proper code.

What I would like to do is generate the codes based on the names. For instance, if the general plan column has "Lower Hillside" then the code column would equal "3" and so on. This would be repeated for a zoning designation as well. As pointed out in the comments this is a 1-to-1 generation. I could see something like the list of general plan names alphabetically assigned 0-x. I'm just not sure how to do that.

  • It sounds like you need to create a lookup table and then use Join Fields to place those lookup values onto your features. Since the general plan designation seems to be the key between the attribute and lookup tables I'm unclear why you have more codes than general plan designations. If you're planning to split some general plans into multiple codes then that adds another level of complexity and needs a more precise description of your requirements. – PolyGeo Feb 20 at 23:52
  • The general plan of Neighborhood Community Commercial (NCC) has three associated codes which reference the zoning that conforms under NCC. So, for instance, the GP code for NCC is 2, 4, and 6--which refer back to the zoning Commercial General, Commercial Neighborhood, and Commercial Pedestrian, respectively. Would there be a method to, for instance, update the GP code for NCC from 2, 4, and 6 to something like 2, 4, 6, 8 if I find another conforming zoning? Or remove a number to make it 2 and 4 if code 6 is no longer a conforming zoning designation? – Therow Feb 21 at 0:11
  • 1
    What is the relationship between general plans and zoning designations? One-to-one, one-to-many, many-to-one or many-to-many. @PolyGeo's suggestion seems like the way to go, but as that comment suggests, it depends on if one general plan can result in more than one zone designation (or one of several zone designations) or not. – Son of a Beach Feb 21 at 0:18
  • Yeah I may have been a little in the weeds on this one. The general plan code itself is a 1-to-1. The zoning code would be a 1-to-1. The one-to-many process occurs in the symbology where I add these fields up in the unique values option and scrutinize them there. – Therow Feb 21 at 0:23
  • I think your question would be much clearer with a picture of a few polygons and the before and after attribute values that you are trying to achieve on those particular polygons. – PolyGeo Feb 21 at 0:42
1

You can use an Update Cursor to populate a field based on values in another field.

The following example has two fields general_plan, which has classified zoning data (e.g. "Residential") and coded which is an empty string field. You can use if/elif/else statements to add an integer classification code. For example

import arcpy

fc = r'C:\path\to\your\geodatabase.gdb\featureclass'

with arcpy.da.UpdateCursor(fc, ("general_plan", "coded")) as cursor:
    for row in cursor:
        if row[0] == "Lower Hillside":
            row[1] = 3 
        elif row[0] == "Residential Neighborhood":
            row[1] = 4
        elif row[0] == "Commercial Property":
            row[1] = 5
        else:
            row[1] = 0 # All other values
        cursor.updateRow(row)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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