Calculate Field problem Please Help

Discussion created by scottaidh on Apr 4, 2013
Latest reply on Apr 4, 2013 by csny490

I've written a script that narrows down a selection of points (cities) and then adds a field called CITYNAME to the feature class.  I need to update the new CITYNAME field with the same values as the NAME field in the same feature class but it doesn't update them although it shows as having run successfully.

I need to do this so that I can spatially join this points (cities) dataset to polygons (counties) and lines (roads) because all three of them have the same fieldname called NAME. 

I'm using ArcGIS v10.0 and any help would be appreciated as I've tried various methods like CalculateField and UpdateCursor to no avail.



# Description: Extract features to a new feature class based on a Location and an attribute query
# then add field called CITYNAME and update it with the NAME field from the cities layer

# import system modules
import arcpy
from arcpy import env
import os

# set overwrite option
arcpy.env.overwriteOutput = True

# Put in error trapping in case an error occurs when running tool
    # Make a layer from the cities feature class

    # Select all cities that are within 30km of an interstate
    arcpy.SelectLayerByLocation_management("citiesL", "WITHIN_A_DISTANCE", "H:/working/Findsites.gdb/interstates", "30 KILOMETERS", "NEW_SELECTION")

    # Within the selection (done above) further select only those cities that have a university and low crime rate
    arcpy.SelectLayerByAttribute_management("citiesL", "SUBSET_SELECTION", "UNIVERSITY = 1 AND CRIME_INDE <= 0.02")
    # Make a layer from the counties feature class
    # From the counties layer select only those counties with a large enough workforce and number of farms
    arcpy.SelectLayerByAttribute_management("countiesL", "NEW_SELECTION", "AGE_18_64 >= 25000 AND NO_FARMS87 >= 500")

    # Select all cities that intersect counties that meet work force and number of farms criteria
    arcpy.SelectLayerByLocation_management("citiesL", "INTERSECT", "countiesL", "", "SUBSET_SELECTION")
    # Write the selected features to a new featureclass
    arcpy.CopyFeatures_management("citiesL", "H:/working/Findsites.gdb/CityList")
    # create a new field called CITYNAME to replace NAME because other datasets have a NAME field
    arcpy.AddField_management("H:/working/Findsites.gdb/CityList", "CITYNAME", "TEXT", "", "", "25")
    expression1 = '!MP_VAL!'
    arcpy.CalculateField_management(CityList, CITYNAME, expression1, "PYTHON", "")
    #Calculate Field - update new CITYNAME field with NAME field
    # arcpy.AddMessage("Calculating Updated Field...")
    # Expression = "'{0}'".format(arcpy.GetValue(NAME))
    # single quoted string literal
    # arcpy.CalculateField_management(CityList, CITYNAME, Expression, "PYTHON")
    # If an error occurred print the message to the screen
    print arcpy.GetMessages()